Skip to content

Instantly share code, notes, and snippets.

@jrmehle
Created November 30, 2010 02:03
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 jrmehle/721005 to your computer and use it in GitHub Desktop.
Save jrmehle/721005 to your computer and use it in GitHub Desktop.
module Paperclip
module Dimension
def get_size_of(name, thumbnail=nil)
return '0x0' unless get_path_of(name, thumbnail)
Geometry.from_file(get_path_of(name, thumbnail)).to_s
end
# calculates width using processor
def get_width_of(name, thumbnail=nil)
return 0 unless get_path_of(name, thumbnail)
Geometry.from_file(get_path_of(name, thumbnail)).width.to_i
end
# calculates height using processor
def get_height_of(name, thumbnail=nil)
return 0 unless get_path_of(name, thumbnail)
Geometry.from_file(get_path_of(name, thumbnail)).height.to_i
end
#path to the attachment
def get_path_of(name, thumbnail=nil)
attachment_for(name).path(thumbnail)
end
end
end
Paperclip::InstanceMethods.send(:include, Paperclip::Dimension)
@jrmehle
Copy link
Author

jrmehle commented Nov 30, 2010

Added the ability to get at the dimensions of thumbnails in addition to the original.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment