Skip to content

Instantly share code, notes, and snippets.

@ilpoldo
Forked from bhauman/image.rb
Created February 24, 2010 18:37
Show Gist options
  • Save ilpoldo/313702 to your computer and use it in GitHub Desktop.
Save ilpoldo/313702 to your computer and use it in GitHub Desktop.
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