Module: DynamicImage::Model::Transformations
- Included in:
- DynamicImage::Model
- Defined in:
- lib/dynamic_image/model/transformations.rb
Overview
DynamicImage Model Transformations
Transformations that rewrite the stored file. Per-request processing never touches it.
Both methods replace the data and update the stored dimensions, adjusting the crop to match. Neither saves the record.
Instance Method Summary collapse
-
#resize(max_size) ⇒ self
Resizes the image, replacing the stored file with a smaller one.
-
#rotate(degrees = 90) ⇒ self
Rotates the image, taking the crop and crop gravity with it.
Instance Method Details
#resize(max_size) ⇒ self
Resizes the image, replacing the stored file with a smaller one. The crop is scaled along with it.
16 17 18 19 20 21 22 |
# File 'lib/dynamic_image/model/transformations.rb', line 16 def resize(max_size) transform_image do |image| resized = image.resize(real_size.constrain_both(max_size)) scale_crop(resized.size) resized end end |
#rotate(degrees = 90) ⇒ self
Rotates the image, taking the crop and crop gravity with it.
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/dynamic_image/model/transformations.rb', line 33 def rotate(degrees = 90) 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 transform_image do |image| rotate_dimensions(real_size.x, real_size.y, degrees) image.rotate(degrees) end end |