Class: Alchemy::EssencePicture
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Alchemy::EssencePicture
- Includes:
- Picture::Transformations
- Defined in:
- app/models/alchemy/essence_picture.rb
Instance Method Summary collapse
-
#allow_image_cropping?(options = {}) ⇒ Boolean
Show image cropping link for content and options?.
-
#cropping_mask ⇒ Object
A Hash of coordinates suitable for the graphical image cropper.
-
#picture_url(options = {}) ⇒ Object
The url to show the picture.
-
#preview_text(max = 30) ⇒ Object
The name of the picture used as preview text in element editor views.
-
#serialized_ingredient ⇒ Object
Returns a serialized ingredient value for json api.
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
Instance Method Details
#allow_image_cropping?(options = {}) ⇒ Boolean
Show image cropping link for content and options?
88 89 90 91 92 93 94 |
# File 'app/models/alchemy/essence_picture.rb', line 88 def allow_image_cropping?( = {}) content && content.settings_value(:crop, ) && picture && picture.can_be_cropped_to( content.settings_value(:image_size, ), content.settings_value(:upsample, ) ) end |
#cropping_mask ⇒ Object
A Hash of coordinates suitable for the graphical image cropper.
74 75 76 77 78 79 80 |
# File 'app/models/alchemy/essence_picture.rb', line 74 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 = {}) ⇒ Object
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'
57 58 59 60 |
# File 'app/models/alchemy/essence_picture.rb', line 57 def picture_url( = {}) return if picture.nil? routes.show_picture_path(picture_params()) end |
#preview_text(max = 30) ⇒ Object
The name of the picture used as preview text in element editor views.
67 68 69 70 |
# File 'app/models/alchemy/essence_picture.rb', line 67 def preview_text(max = 30) return "" if picture.nil? picture.name.to_s[0..max - 1] end |
#serialized_ingredient ⇒ Object
Returns a serialized ingredient value for json api
83 84 85 |
# File 'app/models/alchemy/essence_picture.rb', line 83 def serialized_ingredient picture_url(content.settings) end |