Module: Alchemy::PictureThumbnails
- Extended by:
- ActiveSupport::Concern
- Included in:
- Ingredients::Picture
- Defined in:
- app/models/concerns/alchemy/picture_thumbnails.rb
Overview
Picture thumbnails and cropping concerns
Instance Method Summary collapse
-
#allow_image_cropping? ⇒ Boolean
Show image cropping link for ingredient.
-
#image_cropper_settings ⇒ Object
Settings for the graphical JS image cropper.
-
#picture_url(options = {}) ⇒ String
The url to show the picture.
-
#picture_url_options ⇒ HashWithIndifferentAccess
Picture rendering options.
-
#thumbnail_url ⇒ String
Returns an url for the thumbnail representation of the assigned picture.
-
#thumbnail_url_options ⇒ HashWithIndifferentAccess
Thumbnail rendering options.
Instance Method Details
#allow_image_cropping? ⇒ Boolean
Show image cropping link for ingredient
104 105 106 107 108 109 110 |
# File 'app/models/concerns/alchemy/picture_thumbnails.rb', line 104 def allow_image_cropping? settings[:crop] && picture && picture.can_be_cropped_to?( settings[:size], settings[:upsample] ) && !!picture.image_file end |
#image_cropper_settings ⇒ Object
Settings for the graphical JS image cropper
92 93 94 95 96 97 98 99 100 101 |
# File 'app/models/concerns/alchemy/picture_thumbnails.rb', line 92 def image_cropper_settings Alchemy::ImageCropperSettings.new( render_size: dimensions_from_string(render_size.presence || settings[:size]), default_crop_from: default_crop_from, default_crop_size: default_crop_size, fixed_ratio: settings[:fixed_ratio], image_width: picture&.image_file_width, image_height: picture&.image_file_height ).to_h end |
#picture_url(options = {}) ⇒ String
The url to show the picture.
Takes all values like name
and crop sizes (crop_from
, crop_size
from the build in graphical image cropper) and also adds the security token.
You typically want to set the size the picture should be resized to.
Example:
picture_view.picture_url(size: '200x300', crop: true, format: 'gif')
# '/pictures/1/show/200x300/crop/cats.gif?sh=765rfghj'
37 38 39 40 41 |
# File 'app/models/concerns/alchemy/picture_thumbnails.rb', line 37 def picture_url( = {}) return if picture.nil? picture.url(.merge()) || "missing-image.png" end |
#picture_url_options ⇒ HashWithIndifferentAccess
Picture rendering options
Returns the default_render_format
of the associated Alchemy::Picture
together with the crop_from
and crop_size
values
49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'app/models/concerns/alchemy/picture_thumbnails.rb', line 49 def return {} if picture.nil? crop = !!settings[:crop] { format: picture.default_render_format, crop: crop, crop_from: crop && crop_from.presence || nil, crop_size: crop && crop_size.presence || nil, size: settings[:size] }.with_indifferent_access end |
#thumbnail_url ⇒ String
Returns an url for the thumbnail representation of the assigned picture
It takes cropping values into account, so it always represents the current image displayed in the frontend.
69 70 71 72 73 |
# File 'app/models/concerns/alchemy/picture_thumbnails.rb', line 69 def thumbnail_url return if picture.nil? picture.url() || "alchemy/missing-image.svg" end |
#thumbnail_url_options ⇒ HashWithIndifferentAccess
Thumbnail rendering options
78 79 80 81 82 83 84 85 86 87 88 89 |
# File 'app/models/concerns/alchemy/picture_thumbnails.rb', line 78 def crop = !!settings[:crop] { size: "160x120", crop: crop, crop_from: crop && crop_from.presence || default_crop_from&.join("x"), crop_size: crop && crop_size.presence || default_crop_size&.join("x"), flatten: true, format: picture&.image_file_format || "jpg" } end |