简体   繁体   English

如何优化使用Paperclip&Rails上传的图像?

[英]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.

相关问题 如何在Heroku上处理Rails应用程序的用户上传照片文件(使用回形针)? - How can I handle user-uploaded photo files for a Rails app (using paperclip) on Heroku? Rails使用回形针调整上传图像的大小 - Rails resize uploaded images with Paperclip Rails回形针不显示上传的图像 - Rails Paperclip not showing uploaded images 如何使用重新处理将已上传的Paperclip图像调整为s3? (导轨) - How to resize already uploaded Paperclip images to s3 using reprocess? (Rails) Ruby on Rails-回形针-限制上传的图像数量 - Ruby on Rails - Paperclip - Limit amount of images uploaded 如何在回形针中指定可以上传到服务器的文件 - How can I specify what files can be uploaded to the server in paperclip 如何使用Rspec测试使用Paperclip的模型是否验证上传文件的大小? - How can I use Rspec to test that a model using Paperclip is validating the size of an uploaded file? 如果没有图像上传到回形针,如何避免验证失败? - How can I avoid failed validation if no image is uploaded to paperclip? 使用曲别针通过我的rails-app上传的一些图像未出现在heroku上 - Some images uploaded through my rails-app using paperclip not appearing on heroku 我可以使用Paperclip在Rails中发表评论吗? - Can I use Paperclip for comments in rails and how?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM