Skip to content


Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP


How to retrieve image dimensions? #790

agis- opened this Issue · 9 comments

5 participants

Agis Anastasopoulos Andy Stewart Yuval Kordov Prem Sichanugrist Geoffrey Hichborn
Agis Anastasopoulos

Is it possible somehow to retrieve the dimensions of a thumbnail generated by Paperclip?

For example it would be useful to have something like this-> @product.image.width; @product.image.height.

Andy Stewart

I don't know about within Paperclip, but outside Paperclip you could try Dimensions.

Yuval Kordov
before_save :extract_dimensions

  # @note Do this after resize operations to account for auto-orientation.
  def extract_dimensions
    tempfile = upload.queued_for_write[:original]
    unless tempfile.nil?
      geometry = Paperclip::Geometry.from_file(tempfile)
      self.dimensions = [geometry.width.to_i, geometry.height.to_i]
Prem Sichanugrist

You'll be able to do @product.image.geometry.width and @product.image.geometry.height in Paperclip 3.0.1.

Prem Sichanugrist sikachu closed this
Yuval Kordov

Don't these calls download the file in order to run the geometry calculations? If so, this is expensive and impractical, which is why I personally do it once on a before_save.

Prem Sichanugrist

Yep, you can. I'd love to take a pull request for a magic attachment_width/attachment_height attribute too, but this is a cheap (easy to implement) solution when your attachment is already saved.

Yuval Kordov

I wouldn't suggest anyone who's using s3 use those methods.

Prem Sichanugrist

Yeah, and there's no way to get that attachment metadata without fetching the file down anyway after you've saved it. :)

That code is broken anyway, so I'm reverting it.

Prem Sichanugrist sikachu reopened this
Geoffrey Hichborn

Checkout #835

Prem Sichanugrist

I think i am going to merge #835 into 3.1, so closing this.

Prem Sichanugrist sikachu closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.