34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
|
# File 'lib/paperclip-dimension.rb', line 34
def save_dimensions_for(name)
if self.class.respond_to?(:attachment_definitions)
opts = self.class.attachment_definitions[name]
else
opts = ::Paperclip::Tasks::Attachments.definitions_for(self.class)[name]
end
styles = [:original]
styles += opts[:styles].keys if opts[:styles]
dimension_hash = {}
styles.each do |style|
attachment = self.send name
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
|