34
35
36
37
38
39
40
41
42
43
44
45
|
# 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
|