Skip to content

Instantly share code, notes, and snippets.

@felipeelias
Created September 15, 2008 01:41
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 4 You must be signed in to fork a gist
  • Save felipeelias/10790 to your computer and use it in GitHub Desktop.
Save felipeelias/10790 to your computer and use it in GitHub Desktop.
# Para salvar a altura e largura das imagens enviadas pelo plugin paperclip, utilize o callback abaixo
#
# class Document < ActiveRecord::Base
#
# has_attached_file :document, :styles => { :medium => "300x300>" }
#
# before_save :save_dimensions
#
# def save_dimensions
# if document.image?
# self.width = document.width
# self.height = document.height
# end
# end
#
# end
module Paperclip
class Attachment
def width(style = default_style)
Paperclip::Geometry.from_file(to_file(style)).width
end
def height(style = default_style)
Paperclip::Geometry.from_file(to_file(style)).height
end
def image?(style = default_style)
to_file(style).image?
end
end
module Upfile
def image?
["image/jpeg", "image/tiff", "image/png", "image/gif", "image/bmp"].include?(content_type)
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment