module ChunkyPNG::Canvas::Operations
def crop!(x, y, crop_width, crop_height)
-
(ChunkyPNG::OutOfBounds)
- when the crop dimensions plus the given coordinates
Returns:
-
(ChunkyPNG::Canvas)
- Returns itself, but cropped.
Parameters:
-
crop_height
(Integer
) -- The height of the image to be cropped. -
crop_width
(Integer
) -- The width of the image to be cropped. -
y
(Integer
) -- The y-coordinate of the top left corner of the image to be cropped. -
x
(Integer
) -- The x-coordinate of the top left corner of the image to be cropped.
def crop!(x, y, crop_width, crop_height) raise ChunkyPNG::OutOfBounds, "Image width is too small!" if crop_width + x > width raise ChunkyPNG::OutOfBounds, "Image width is too small!" if crop_height + y > height new_pixels = [] for cy in 0...crop_height do new_pixels += pixels.slice((cy + y) * width + x, crop_width) end replace_canvas!(crop_width, crop_height, new_pixels) end