Skip to content

Instantly share code, notes, and snippets.

@jess
Created January 5, 2012 18:36
Show Gist options
  • Save jess/1566558 to your computer and use it in GitHub Desktop.
Save jess/1566558 to your computer and use it in GitHub Desktop.
#carrierwave, get image width and height of image (using the MiniMagick gem)
#stick this in your uploader (ex: uploaders/file_uploader.rb)
def width
@image ||= get_minimagick_image
@image[:width]
end
def height
@image ||= get_minimagick_image
@image[:height]
end
def get_minimagick_image
MiniMagick::Image.open(Rails.root.join("public/#{self.url}"))
end
#now you can call it like this from anywhere
#file is my uploader object
@image = Image.find(1)
@image.file.height
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment