Skip to content

Instantly share code, notes, and snippets.

@bcalloway
Created June 11, 2010 15:32
Show Gist options
  • Save bcalloway/434640 to your computer and use it in GitHub Desktop.
Save bcalloway/434640 to your computer and use it in GitHub Desktop.
Method to determine the orientation of an image using Paperclip
# 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