user502052 user502052 -4 years ago 135
Ruby Question

Is it possible to compress the size (bytes) of an image to a specific size using Paperclip?

I am running Ruby on Rails 3 and I would like to know if it is possible to compress the size (bytes) of an image to a specific size using the Paperclip plugin/gem.

For example, if I upload an image of 1500kb, I would like to have a thumb resized to 10kb.

At this time in my model file I have:

:styles => {
:thumb => {
:geometry => '50x50#',
:quality => 50,
:format => :jpg
},
}


If so, how to do that?

Answer Source

I don't believe that there's a way to compress something to a specific output size. For one thing, it may not be possible to compress something down to that size. With Jpeg you can adjust the 'quality' parameter but there's no real way to predict what the exact compression ratio will be.

If all you need is thumbnails that are under a certain file size, try compressing the image at one 'quality' value and then incrementally adjusting it until the output size meets your requirements.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download