Jim Neath

Manchester based Ruby on Rails & Facebook App Developer

If you ever need to know if an image is portrait or landscape in orientation, you can do the following (assuming you have an orientation attribute on your model:

class Image < ActiveRecord::Base
  # Paperclip
  has_attached_file :file
  # Callbacks
  before_create :set_orientation
  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'
blog comments powered by Disqus

I am available for freelance work! Click here to email me.

Jim Neath is a Freelance Ruby on Rails & Facebook app developer from Manchester, UK, currently working for Engine Yard.