Created
June 11, 2010 15:32
-
-
Save bcalloway/434640 to your computer and use it in GitHub Desktop.
Method to determine the orientation of an image using Paperclip
This file contains 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
# via http://jimneath.org/2010/06/10/calculating-an-images-orientation-using-paperclip/ | |
class Image < ActiveRecord::Base | |
# Paperclip | |
has_attached_file :file | |
# Callbacks | |
before_create :set_orientation | |
protected | |
def set_orientation | |
original_file = self.file.to_file(:original) | |
dimensions = Paperclip::Geometry.from_file(original_file) | |
self.orientation = (dimensions.width > dimensions.height) ? 'landscape' : 'portrait' | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment