Is possible with carrierwave create a version (for example thumb) only if the image is larger than the size of the version??
Example:
version :thumb, :if => :is_thumbnable? do
process :resize_to_fit => [32,nil]
end
protected
def is_thumbnable?(file)
image ||= MiniMagick::Image.open(file.path)
if image.nil?
if image['width'] >= 32 || image['height'] >= 32
true
else
false
end
else
false
end
end
Actually @Roza solution didn't work for me. I had to modify method like this:
I use rmagick (2.13.2) and rails 3.2.13, carrierwave (0.8.0)
I defined method in which if image exceed given width then manipulate it to your size the 32 pixels in this case. Put this code in your ImageUploader:
I tried them and it didn't work for me. I get the server blocked when resizing to large images in development.
So I get a look at the documentation: http://carrierwave.rubyforge.org/rdoc/classes/CarrierWave/RMagick.html
There is a wonderful function:
resize_to_limit(width, height)
My code look like this:
It resize to fit the width only if it's larger, respecting the ratio w/h.