Created
September 15, 2008 01:41
-
-
Save felipeelias/10790 to your computer and use it in GitHub Desktop.
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
# 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