Skip to content

How to: Get version image dimensions

khelll edited this page Oct 25, 2011 · 16 revisions

Simple trick to get the image dimensions generated by some version:

class LogoUploader < CarrierWave::Uploader::Base 
  # ... 
  version :show do
    # do the processing you need
    process :resize_to_limit => [500, 500]
    # and, here comes the trick, use some processor to access the file generated
    process :get_version_dimensions 
  end

  def get_version_dimensions
    width, height = `identify -format "%wx%h" #{file.path}`.split(/x/) 
  end
  # ...
end

Clone this wiki locally