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?(options = {}) ⇒ Boolean
Show image cropping link for content and options?.
- #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(options = {}) ⇒ String
Returns an url for the thumbnail representation of the assigned picture.
Methods included from Picture::Transformations
#can_be_cropped_to, #crop, #crop_size?, #default_mask, #image_size, #landscape_format?, #portrait_format?, #render_size?, #resize, #sizes_from_string, #square_format?, #thumbnail_size
Methods inherited from BaseRecord
Instance Method Details
#allow_image_cropping?(options = {}) ⇒ Boolean
Show image cropping link for content and options?
141 142 143 144 145 146 147 |
# File 'app/models/alchemy/essence_picture.rb', line 141 def allow_image_cropping?( = {}) content && content.settings_value(:crop, ) && picture && picture.can_be_cropped_to( content.settings_value(:size, ), content.settings_value(:upsample, ) ) 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.
125 126 127 128 129 130 131 |
# File 'app/models/alchemy/essence_picture.rb', line 125 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'
64 65 66 67 68 |
# File 'app/models/alchemy/essence_picture.rb', line 64 def picture_url( = {}) return if picture.nil? picture.url .merge() 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
76 77 78 79 80 81 82 83 84 85 |
# File 'app/models/alchemy/essence_picture.rb', line 76 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.
117 118 119 120 |
# File 'app/models/alchemy/essence_picture.rb', line 117 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(options = {}) ⇒ 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.
93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 |
# File 'app/models/alchemy/essence_picture.rb', line 93 def thumbnail_url( = {}) return if picture.nil? crop = crop_values_present? || content.settings_value(:crop, ) size = render_size || content.settings_value(: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() end |