Class: Alchemy::PictureVariant
- Inherits:
-
Object
- Object
- Alchemy::PictureVariant
- Extended by:
- Forwardable
- Includes:
- Logger, Alchemy::Picture::Transformations
- Defined in:
- app/models/alchemy/picture_variant.rb
Overview
Represents a rendered picture
Resizes, crops and encodes the image with imagemagick
Constant Summary
Constants included from Alchemy::Picture::Transformations
Alchemy::Picture::Transformations::THUMBNAIL_HEIGHT, Alchemy::Picture::Transformations::THUMBNAIL_WIDTH
Instance Attribute Summary collapse
-
#picture ⇒ Object
readonly
Returns the value of attribute picture.
-
#render_format ⇒ Object
readonly
Returns the value of attribute render_format.
Instance Method Summary collapse
-
#image ⇒ Dragonfly::Attachment|Dragonfly::Job
Process a variant of picture.
-
#initialize(picture, options = {}) ⇒ PictureVariant
constructor
A new instance of PictureVariant.
Methods included from Alchemy::Picture::Transformations
#crop, #crop_size?, #default_mask, #landscape_format?, #portrait_format?, #render_size?, #resize, #square_format?, #thumbnail_size
Methods included from Logger
Constructor Details
#initialize(picture, options = {}) ⇒ PictureVariant
Returns a new instance of PictureVariant.
37 38 39 40 41 42 43 |
# File 'app/models/alchemy/picture_variant.rb', line 37 def initialize(picture, = {}) raise ArgumentError, "Picture missing!" if picture.nil? @picture = picture @options = @render_format = [:format] || picture.default_render_format end |
Instance Attribute Details
#picture ⇒ Object (readonly)
Returns the value of attribute picture.
16 17 18 |
# File 'app/models/alchemy/picture_variant.rb', line 16 def picture @picture end |
#render_format ⇒ Object (readonly)
Returns the value of attribute render_format.
16 17 18 |
# File 'app/models/alchemy/picture_variant.rb', line 16 def render_format @render_format end |
Instance Method Details
#image ⇒ Dragonfly::Attachment|Dragonfly::Job
Process a variant of picture
49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'app/models/alchemy/picture_variant.rb', line 49 def image image = image_file raise MissingImageFileError, "Missing image file for #{picture.inspect}" if image.nil? image = processed_image(image, @options) image = encoded_image(image, @options) image rescue MissingImageFileError, WrongImageFormatError => e log_warning(e.) nil end |