Module: Mongoid::Paperclip::ImageDimension

Extended by:
ActiveSupport::Concern
Defined in:
lib/mongoid_paperclip_image_dimension.rb

Defined Under Namespace

Modules: ClassMethods

Instance Method Summary collapse

Instance Method Details

#save_dimensions_for(attachment_field) ⇒ Object



37
38
39
40
41
42
43
44
45
46
# File 'lib/mongoid_paperclip_image_dimension.rb', line 37

def save_dimensions_for(attachment_field)
  styles = self.class.attachment_definitions[attachment_field][:styles].keys + [:original]
  dimension_hash = {}
  styles.each do |style|
    attachment = self.send attachment_field
    geo = Paperclip::Geometry.from_file(attachment.queued_for_write[style])
    dimension_hash[style] = [ geo.width.to_i, geo.height.to_i ]
  end
  self.send "#{attachment_field}_dimensions=", dimension_hash
end