Reputation: 12042
When I upload a photo to my Rails application using PaperClip how can I know the dimensions (width & Height) of it?
Upvotes: 0
Views: 199
Reputation: 795
http://rdoc.info/github/thoughtbot/paperclip/master/Paperclip/Geometry
In your model:
before_save :set_dimensions
def set_dimensions
tempfile = self.local_avatar.queued_for_write[:original]
unless tempfile.nil?
dimensions = Paperclip::Geometry.from_file(tempfile)
self.width = dimensions.width
self.height = dimensions.height
end
end
You need to change local_avatar. And have width and height column in your model.
source: link text
Upvotes: 1