Module: Alchemy::Picture::Transformations
- Extended by:
- ActiveSupport::Concern
- Included in:
- Alchemy::PictureVariant
- Defined in:
- app/models/alchemy/picture/transformations.rb
Overview
This concern can extend classes that expose image_file, image_file_width and image_file_height. It provides methods for cropping and resizing.
Instance Method Summary collapse
-
#crop(size, crop_from = nil, crop_size = nil, upsample = false) ⇒ Object
Returns the rendered cropped image.
-
#crop_size? ⇒ Boolean
Returns true if the class we’re included in has a meaningful crop_size attribute.
-
#render_size? ⇒ Boolean
Returns true if the class we’re included in has a meaningful render_size attribute.
-
#resize(size, upsample = false) ⇒ Object
Returns the rendered resized image using imagemagick directly.
Instance Method Details
#crop(size, crop_from = nil, crop_size = nil, upsample = false) ⇒ Object
Returns the rendered cropped image. Tries to use the crop_from and crop_size parameters. When they can’t be parsed, it just crops from the center.
17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'app/models/alchemy/picture/transformations.rb', line 17 def crop(size, crop_from = nil, crop_size = nil, upsample = false) raise "No size given!" if size.empty? render_to = inferred_sizes_from_string(size) if crop_from && crop_size top_left = point_from_string(crop_from) crop_dimensions = inferred_sizes_from_string(crop_size) xy_crop_resize(render_to, top_left, crop_dimensions, upsample) else center_crop(render_to, upsample) end end |
#crop_size? ⇒ Boolean
Returns true if the class we’re included in has a meaningful crop_size attribute
44 45 46 |
# File 'app/models/alchemy/picture/transformations.rb', line 44 def crop_size? respond_to?(:crop_size) && !crop_size.nil? && !crop_size.empty? end |
#render_size? ⇒ Boolean
Returns true if the class we’re included in has a meaningful render_size attribute
38 39 40 |
# File 'app/models/alchemy/picture/transformations.rb', line 38 def render_size? respond_to?(:render_size) && render_size.present? end |
#resize(size, upsample = false) ⇒ Object
Returns the rendered resized image using imagemagick directly.
32 33 34 |
# File 'app/models/alchemy/picture/transformations.rb', line 32 def resize(size, upsample = false) image_file.thumbnail(upsample ? size : "#{size}>") end |