Class: Paperclip::SaveDimensions

Inherits:
Processor
  • Object
show all
Defined in:
lib/retina_rails/processors/paperclip.rb

Instance Method Summary collapse

Instance Method Details

#makeObject

Stores the original dimensions of the image as a serialized Hash in to the model



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/retina_rails/processors/paperclip.rb', line 7

def make
  model     = attachment.instance
  file_path = file.path rescue nil
  style     = options[:style]

  if file_path
    width, height = `identify -format "%wx%h" '#{file_path}'`.split(/x/) ## Read dimensions

    ## Set original height and width attributes on model
    model.retina_dimensions = (model.retina_dimensions || {}).deep_merge!(
      attachment.name => {
        style => {
          :width  => width.to_i  / 2,
          :height => height.to_i / 2
        }
      }
    )
  end

  file
end