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?
136 137 138 139 140 141 142 |
# File 'app/models/alchemy/essence_picture.rb', line 136 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
144 145 146 |
# File 'app/models/alchemy/essence_picture.rb', line 144 def crop_values_present? crop_from.present? && crop_size.present? end |
#cropping_mask ⇒ Hash
A Hash of coordinates suitable for the graphical image cropper.
120 121 122 123 124 125 126 |
# File 'app/models/alchemy/essence_picture.rb', line 120 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'
60 61 62 63 64 |
# File 'app/models/alchemy/essence_picture.rb', line 60 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
72 73 74 75 76 77 78 79 80 |
# File 'app/models/alchemy/essence_picture.rb', line 72 def return {} if picture.nil? { format: picture.default_render_format, crop_from: crop_from.presence, crop_size: crop_size.presence }.with_indifferent_access end |
#preview_text(max = 30) ⇒ String
The name of the picture used as preview text in element editor views.
112 113 114 115 |
# File 'app/models/alchemy/essence_picture.rb', line 112 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
131 132 133 |
# File 'app/models/alchemy/essence_picture.rb', line 131 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.
88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 |
# File 'app/models/alchemy/essence_picture.rb', line 88 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 |