[英]How can I optimize images uploaded using Paperclip & Rails?
Does anyone know how to optimize image size through paperclip? 有谁知道如何通过回形针优化图像大小?
In my Graphic model I have the following: 在我的Graphic模型中,我有以下内容:
has_attached_file :graphic,
:styles => {
:home => ['120x90',:jpg],
:thumb => ['70x70',:jpg]
}
By optimize I mean, reduce the filesize of each of :home & :thumb graphics once paperclip creates them, Google's speed test tells me that I should be able to reduce these by 70 - 90%. 通过优化我的意思是,减少每个文件大小:home&:thumb图形一旦回形针创建它们,谷歌的速度测试告诉我,我应该能够将这些减少70-90%。
I think I can do this by creating a perclip processor, but not really sure where to start. 我想我可以通过创建一个perclip处理器来做到这一点,但不确定从哪里开始。
Kind of stumped on this one, any help / hints much appreciated! 有点难过这个,任何帮助/提示非常感谢!
(Rails 2.3) (Rails 2.3)
There's a gem that allows you to do this easily with Paperclip: 有一个宝石可以让你使用Paperclip轻松完成这项工作:
https://github.com/janfoeh/paperclip-optimizer https://github.com/janfoeh/paperclip-optimizer
And this gem to image compression processor for Paperclip: 而这个宝石到Paperclip的图像压缩处理器:
https://github.com/emrekutlu/paperclip-compression https://github.com/emrekutlu/paperclip-compression
Check out the quality option. 查看质量选项。 I've read that 75 is the best setting for balancing quality and the resulting size of the image. 我已经读过75是平衡质量和图像尺寸的最佳设置。
has_attached_file :photo,
:styles => {
:small => {
:geometry => '38x38#',
:quality => 40,
:format => 'JPG'
},
:medium => {
:geometry => '92x92#',
:quality => 50
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.