Sha256: 6a9923b891adb4c498e04b38b458edabfd53a6383be3af9c430ab06da645f10e

Contents?: true

Size: 788 Bytes

Versions: 4

Compression:

Stored size: 788 Bytes

Contents

module Paperclip
  class SaveDimensions < Paperclip::Processor

    ##
    # Stores the original dimensions of the image as a serialized Hash in to the model
    #
    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

  end # SaveDimensions
end # Paperclip

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
retina_rails-2.0.5 lib/retina_rails/processors/paperclip.rb
retina_rails-2.0.4 lib/retina_rails/processors/paperclip.rb
retina_rails-2.0.3 lib/retina_rails/processors/paperclip.rb
retina_rails-2.0.2 lib/retina_rails/processors/paperclip.rb