When using Paperclip to save an attached image, how do I get & store the dimensions of the image? Best way is to create two fields to store the width & height and then just populate those fields when the image loads. (Other solutions, like reading it dynamically each, incur a lot of unnecessary disk activity.) Be sure to checkout some basic tutorials on Paperclip if you are unfamiliar with it generally. (see references below 1 2 3)

Step by step instructions.

1. create a new file at lib/paperclip_processors/thumbnail_with_dimensions.rb

2. Paste the contents of this gist into the newly created file:
http://gist.github.com/343678

May 222009

1) be sure to put in your environment file (inside your initializer)

config.gem "paperclip"

2) make sure your form_form has multipart set to true like this:

<% form_for @photo, :html => { :multipart => true } do |f| %>

3) if using passenger, you must put this in config/initializers/paperclip.rb:

if RAILS_ENV == "development"
Paperclip.options[:image_magick_path] = '/opt/local/bin/'
end

(Make sure your imagemagick binaries are really in /opt/local/bin/. You can type /opt/local/bin/convert -v to check. I would recommend the MacPorts installation of ImageMagick and re-install if you are unsure.)

© 2012 Tech Notes Suffusion theme by Sayontan Sinha