Created
November 30, 2010 02:03
-
-
Save jrmehle/721005 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Added the ability to get at the dimensions of thumbnails in addition to the original.