Module: DynamicImage::ImageProcessor::Transform
- Included in:
- DynamicImage::ImageProcessor
- Defined in:
- lib/dynamic_image/image_processor/transform.rb
Overview
ImageProcessor::Transform
Cropping, resizing and rotation. Each operation is applied to every frame of an animated image.
Instance Method Summary collapse
-
#crop(crop_size, crop_start) ⇒ DynamicImage::ImageProcessor
Crops the image.
-
#resize(new_size) ⇒ DynamicImage::ImageProcessor
Resize the image to a new size.
-
#rotate(degrees) ⇒ DynamicImage::ImageProcessor
Rotates the image.
Instance Method Details
#crop(crop_size, crop_start) ⇒ DynamicImage::ImageProcessor
Crops the image.
15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/dynamic_image/image_processor/transform.rb', line 15 def crop(crop_size, crop_start) return self if crop_start == Vector2d(0, 0) && crop_size == size unless valid_crop?(crop_start, crop_size) raise DynamicImage::Errors::InvalidTransformation, "crop size is out of bounds" end each_frame do |frame| frame.crop(crop_start.x, crop_start.y, crop_size.x, crop_size.y) end end |
#resize(new_size) ⇒ DynamicImage::ImageProcessor
Resize the image to a new size. The aspect ratio is not preserved; crop first if that matters.
32 33 34 35 36 37 38 |
# File 'lib/dynamic_image/image_processor/transform.rb', line 32 def resize(new_size) new_size = Vector2d(new_size) apply image.thumbnail_image(new_size.x.to_i, height: new_size.y.to_i, crop: :none, size: :both) end |
#rotate(degrees) ⇒ DynamicImage::ImageProcessor
Rotates the image. The rotation must be a multiple of 90 degrees.
45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/dynamic_image/image_processor/transform.rb', line 45 def rotate(degrees) degrees = degrees.to_i % 360 return self if degrees.zero? if (degrees % 90).nonzero? raise DynamicImage::Errors::InvalidTransformation, "angle must be a multiple of 90 degrees" end each_frame { |frame| frame.rotate(degrees) } end |