Class: Alchemy::EssencePicture
- Inherits:
-
BaseRecord
- Object
- ActiveRecord::Base
- BaseRecord
- Alchemy::EssencePicture
- Includes:
- Picture::Transformations
- Defined in:
- app/models/alchemy/essence_picture.rb
Constant Summary
Constants included from Picture::Transformations
Picture::Transformations::THUMBNAIL_HEIGHT, Picture::Transformations::THUMBNAIL_WIDTH
Instance Method Summary collapse
-
#allow_image_cropping? ⇒ Boolean
Show image cropping link for content.
- #crop_values_present? ⇒ Boolean
-
#cropping_mask ⇒ Hash
A Hash of coordinates suitable for the graphical image cropper.
-
#picture_url(options = {}) ⇒ String
The url to show the picture.
-
#picture_url_options ⇒ HashWithIndifferentAccess
Picture rendering options.
-
#preview_text(max = 30) ⇒ String
The name of the picture used as preview text in element editor views.
-
#serialized_ingredient ⇒ String
Returns a serialized ingredient value for json api.
-
#thumbnail_url ⇒ String
Returns an url for the thumbnail representation of the assigned picture.
Methods included from Picture::Transformations
#crop, #crop_size?, #default_mask, #landscape_format?, #portrait_format?, #render_size?, #resize, #square_format?, #thumbnail_size
Instance Method Details
#allow_image_cropping? ⇒ Boolean
Show image cropping link for content
141 142 143 144 145 146 147 |
# File 'app/models/alchemy/essence_picture.rb', line 141 def allow_image_cropping? content && content.settings[:crop] && picture && picture.can_be_cropped_to?( content.settings[:size], content.settings[:upsample], ) && !!picture.image_file end |
#crop_values_present? ⇒ Boolean
149 150 151 |
# File 'app/models/alchemy/essence_picture.rb', line 149 def crop_values_present? crop_from.present? && crop_size.present? end |
#cropping_mask ⇒ Hash
A Hash of coordinates suitable for the graphical image cropper.
124 125 126 127 128 129 130 131 |
# File 'app/models/alchemy/essence_picture.rb', line 124 def cropping_mask return if crop_from.blank? || crop_size.blank? crop_from = point_from_string(read_attribute(:crop_from)) crop_size = sizes_from_string(read_attribute(:crop_size)) point_and_mask_to_points(crop_from, crop_size) 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:
essence_picture.picture_url(size: '200x300', crop: true, format: 'gif')
# '/pictures/1/show/200x300/crop/cats.gif?sh=765rfghj'
62 63 64 65 66 |
# File 'app/models/alchemy/essence_picture.rb', line 62 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
74 75 76 77 78 79 80 81 82 83 |
# File 'app/models/alchemy/essence_picture.rb', line 74 def return {} if picture.nil? { format: picture.default_render_format, crop_from: crop_from.presence, crop_size: crop_size.presence, size: content.settings[:size], }.with_indifferent_access end |
#preview_text(max = 30) ⇒ String
The name of the picture used as preview text in element editor views.
115 116 117 118 119 |
# File 'app/models/alchemy/essence_picture.rb', line 115 def preview_text(max = 30) return "" if picture.nil? picture.name.to_s[0..max - 1] end |
#serialized_ingredient ⇒ String
Returns a serialized ingredient value for json api
136 137 138 |
# File 'app/models/alchemy/essence_picture.rb', line 136 def serialized_ingredient picture_url(content.settings) 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.
91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 |
# File 'app/models/alchemy/essence_picture.rb', line 91 def thumbnail_url return if picture.nil? crop = crop_values_present? || content.settings[:crop] size = render_size || content.settings[:size] = { size: thumbnail_size(size, crop), crop: !!crop, crop_from: crop_from.presence, crop_size: crop_size.presence, flatten: true, format: picture.image_file_format, } picture.url() || "alchemy/missing-image.svg" end |