Skip to content

Instantly share code, notes, and snippets.

@bhauman
Created February 14, 2010 00:43
Show Gist options
  • Save bhauman/303767 to your computer and use it in GitHub Desktop.
Save bhauman/303767 to your computer and use it in GitHub Desktop.
Adding Height and Width to paperclip uploads
class Image < ActiveRecord::Base
before_create, :set_width_and_height
has_attached_file :img,
:url => "/system/images/:attachment/:id/:basename.:extension",
:path => "#{Rails.root}/public/system/images/:attachment/:id/:basename.:extension"
def set_width_and_height
# this next line is the magic line
geo = Paperclip::Geometry.from_file(img.to_file(:original))
self.width = geo.width
self.height = geo.height
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment