module Mongoid::Paperclip::ImageDimension

Public Instance Methods

save_dimensions_for(attachment_field) click to toggle source
# 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