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
-
#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
#cropping_mask ⇒ Object
A Hash of coordinates suitable for the graphical image cropper.
75 76 77 78 79 80 81 |
# File 'app/models/alchemy/essence_picture.rb', line 75 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 61 |
# File 'app/models/alchemy/essence_picture.rb', line 57 def picture_url( = {}) return if picture.nil? # routes.show_picture_path(picture_params(options)) Dragonfly.app(:alchemy_pictures).remote_url_for content.essence.picture.image_file.send(:uid) end |
#preview_text(max = 30) ⇒ Object
The name of the picture used as preview text in element editor views.
68 69 70 71 |
# File 'app/models/alchemy/essence_picture.rb', line 68 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
84 85 86 |
# File 'app/models/alchemy/essence_picture.rb', line 84 def serialized_ingredient picture_url(content.settings) end |