Sha256: 038710afb69eeb7d6381b748de3d4c44f1d5df8a0ba6ca1241f08bb65e232f96
Contents?: true
Size: 609 Bytes
Versions: 45
Compression:
Stored size: 609 Bytes
Contents
require 'stringio' # Extension to boost performance of ChunkyPNG module ChunkyPNG class Canvas 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 = Array.new(crop_width * crop_height) for cy in 0...crop_height do new_pixels[cy*crop_width, crop_width] = pixels.slice((cy + y) * width + x, crop_width) end ChunkyPNG::Canvas.new(crop_width, crop_height, new_pixels) end end end
Version data entries
45 entries across 45 versions & 1 rubygems