lib/chunky_png/canvas/operations.rb
# Crops an image, given the coordinates and size of the image that needs
# to be cut out.
#
# This will change the size and content of the current canvas. Use
# {#crop} if you want to have a new canvas returned instead, leaving the
# current canvas intact.
#
# @param [Integer] x The x-coordinate of the top left corner of the image
#   to be cropped.
# @param [Integer] y The y-coordinate of the top left corner of the image
#   to be cropped.
# @param [Integer] crop_width The width of the image to be cropped.
# @param [Integer] crop_height The height of the image to be cropped.
# @return [ChunkyPNG::Canvas] Returns itself, but cropped.
# @raise [ChunkyPNG::OutOfBounds] when the crop dimensions plus the given
#   coordinates are bigger then the original image.
Crops an image, given the coordinates and size of the image that needs
to be cut out.

This will change the size and content of the current canvas. Use
{#crop} if you want to have a new canvas returned instead, leaving the
current canvas intact.
Crops an image given the coordinates and size of the image that needs to be cut out . This will change the size and content of the current canvas . Use { #crop } if you want to have a new canvas returned instead leaving the current canvas intact .
def crop!(x, y, crop_width, crop_height)
        if crop_width + x > width
          raise ChunkyPNG::OutOfBounds, "Original image width is too small!"
        end
        if crop_height + y > height
          raise ChunkyPNG::OutOfBounds, "Original image height is too small!"
        end
        if crop_width == width && x == 0
          replace_canvas!(crop_width, crop_height, pixels.slice(y * width, width * crop_height))
        else
          new_pixels = []
          for cy in 0...crop_height do
            new_pixels.concat pixels.slice((cy + y) * width + x, crop_width)
          end
          replace_canvas!(crop_width, crop_height, new_pixels)
        end
      end
def crop! ( x , y , crop_width , crop_height ) if crop_width + x > width raise ChunkyPNG :: OutOfBounds , "Original image width is too small!" end if crop_height + y > height raise ChunkyPNG :: OutOfBounds , "Original image height is too small!" end if crop_width == width && x == 0 replace_canvas! ( crop_width , crop_height , pixels . slice ( y * width , width * crop_height ) ) else new_pixels = [ ] for cy in 0 ... crop_height do new_pixels . concat pixels . slice ( ( cy + y ) * width + x , crop_width ) end replace_canvas! ( crop_width , crop_height , new_pixels ) end end
Crops an image, given the coordinates and size of the image that needs
to be cut out.
Crops an image given the coordinates and size of the image that needs to be cut out .
# We only need to crop off the top and/or bottom, so we can take a # shortcut.
Returns itself, but cropped.
Returns itself but cropped .
ChunkyPNG::Canvas
[ChunkyPNG::OutOfBounds] when the crop dimensions plus the given coordinates are bigger then the original image.
[ ChunkyPNG :: OutOfBounds ] when the crop dimensions plus the given coordinates are bigger then the original image .
x
<not_specific>
y
<not_specific>
crop_width
<not_specific>
crop_height
<not_specific>
<not_specific>
crop_height The height of the image to be cropped.
crop_height The height of the image to be cropped .