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 collapse
- ANIMATED_IMAGE_FORMATS =
 %w[gif webp]
- TRANSPARENT_IMAGE_FORMATS =
 %w[gif webp png]
- ENCODABLE_IMAGE_FORMATS =
 %w[jpg jpeg webp]
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?, #render_size?, #resize
Methods included from Logger
Constructor Details
#initialize(picture, options = {}) ⇒ PictureVariant
Returns a new instance of PictureVariant.
      41 42 43 44 45 46 47  | 
    
      # File 'app/models/alchemy/picture_variant.rb', line 41 def initialize(picture, = {}) raise ArgumentError, "Picture missing!" if picture.nil? @picture = picture @options = @render_format = ([:format] || picture.default_render_format).to_s end  | 
  
Instance Attribute Details
#picture ⇒ Object (readonly)
Returns the value of attribute picture.
      20 21 22  | 
    
      # File 'app/models/alchemy/picture_variant.rb', line 20 def picture @picture end  | 
  
#render_format ⇒ Object (readonly)
Returns the value of attribute render_format.
      20 21 22  | 
    
      # File 'app/models/alchemy/picture_variant.rb', line 20 def render_format @render_format end  | 
  
Instance Method Details
#image ⇒ Dragonfly::Attachment|Dragonfly::Job
Process a variant of picture
      53 54 55 56 57 58 59 60 61 62 63  | 
    
      # File 'app/models/alchemy/picture_variant.rb', line 53 def image image = image_file raise MissingImageFileError, "Missing image file for #{picture.inspect}" if image.nil? image = processed_image(image, @options) encoded_image(image, @options) rescue MissingImageFileError, WrongImageFormatError => e log_warning(e.) nil end  |