开发者

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 s开发者_开发百科ize 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?


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.


Paperclip processes image based on ImageMagick

As far as I know, there is no an option of ImageMagick can specify the size of the output image.

But you can change the dimension or the quality of the image to reduce the size.

You can use -qualityoption to adjust the quality level from 1 to 100 and the -strip option can remove all profile and other fluff from the image

has_attached_file :photo,
  :styles => {
  :thumb => "100x100#" },
  :convert_options => {
  :thumb => "-quality 75 -strip" }

Paperclip wiki

ImageMagick options

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜