How do I improve Rails / Paperclip image compression inside or ImageMagick / Rmagick?

喜夏-厌秋 提交于 2019-12-11 03:26:06

问题


I'm using Paperclip to crop an image in rails.

I use these convert options:

"-quality #{attachment.quality} \
 -crop #{attachment.width}x#{attachment.height}+#{attachment.x}+#{attachment.y}"

If I crop and save the image as a JPEG with 65% quality the image comes out awful and still has quite a large image size.

However if I use Image Bucket Pro and do the exact same thing, the JPEG comes out looking much better and with a smaller file size.

What can I do to Paperclip (ImageMagick / Rmagick) to improve the image quality and reduce the file size without having such a drastic drop in quality?

Also: I have tried putting a slight Guassian blur on the image and stripping its EXIF data. However this has a negligible effect on the file size.


回答1:


I don't know what's going on within Paperclip itself when you alter the quality percentage, but if you're looking for a great way to reduce image file size while maintaining quality, I'd recommend looking into these gems:

https://github.com/toy/image_optim

https://github.com/grosser/smusher

Since you're using Paperclip, you can also use this to manage it in an automated fashion without the need to use the command line (it uses image optim under the hood):

https://github.com/janfoeh/paperclip-optimizer



来源:https://stackoverflow.com/questions/30263290/how-do-i-improve-rails-paperclip-image-compression-inside-or-imagemagick-rma

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!