module Paperclip::Dimension

Constants

VERSION

Public Class Methods

included(klass) click to toggle source
# File lib/paperclip-dimension.rb, line 5
def self.included(klass)
  klass.extend Paperclip::Dimension::ClassMethods
end

Public Instance Methods

save_dimensions_for(name) click to toggle source
# File lib/paperclip-dimension.rb, line 34
def save_dimensions_for(name)
  dimension_hash = {}
  attachment = self.send(name)
  return unless attachment.content_type =~ %r{^(image|(x-)?application)/(bmp|gif|jpeg|jpg|pjpeg|png|x-png)$}
  styles = [:original]
  styles += attachment.styles.keys if attachment.styles
  styles.each do |style|
    geo = ::Paperclip::Geometry.from_file(attachment.queued_for_write[style])
    dimension_hash[style.to_s] = [ geo.width.to_i, geo.height.to_i ]
  end
  self.send "#{name}_dimensions=", dimension_hash
end