Skip to content

Instantly share code, notes, and snippets.

@jpinnix
Forked from bhauman/image.rb
Created August 12, 2010 19:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jpinnix/521558 to your computer and use it in GitHub Desktop.
Save jpinnix/521558 to your computer and use it in GitHub Desktop.
Paperclip set width and height of an image
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