如何使用 Paperclip 降低上传图像的质量? [英] How can I reduce the quality of an uploading image using Paperclip?

查看:50
本文介绍了如何使用 Paperclip 降低上传图像的质量?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在运行 Ruby on Rails 3,我想使用 Paperclip 插件/gem 降低上传图像的质量.我该怎么做?

I am running Ruby on Rails 3 and I would like to reduce the quality of an uploading image using the Paperclip plugin/gem. How can I do that?

此时在我的模型文件中我有:

At this time in my model file I have:

  has_attached_file :avatar, 
    :styles      => {
      :thumb     => ["50x50#",   :jpg],
      :medium    => ["250x250#", :jpg],
      :original  => ["600x600#", :jpg] }

将图像转换为 .jpg 格式并设置尺寸.

that will convert images in to the .jpg format and will set dimensions.

推荐答案

尝试使用 convert_options.

Try using convert_options.

has_attached_file :avatar, 
                  :styles          => { :thumb => '50x50#' },
                  :convert_options => { :thumb => '-quality 80' }

这篇关于如何使用 Paperclip 降低上传图像的质量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆