【问题标题】:How to change the quality of an upload using Paperclip?如何使用回形针更改上传的质量?
【发布时间】:2016-02-22 07:16:26
【问题描述】:

我到处寻找,我无法理解如何使用回形针更改原件的质量。

在每个线程上,每个人都展示了如何使用生成的缩略图来做到这一点:

 has_attached_file :img, styles: { thumb: "400x400#" }, convert_options: { thumb: '-quality 60 -strip'}

效果很好。但是,我想对原始上传进行此后期处理。我试过了

 has_attached_file :img, styles: { thumb: "400x400#" }, convert_options: { thumb: '-quality 60 -strip', original: '-quality -50 -strip'}

但这不起作用,我的原始照片仍然很大。

谢谢!

【问题讨论】:

  • 下面的答案对你有用吗?
  • 不,它没有:) 请参阅下面的评论

标签: ruby-on-rails upload imagemagick paperclip image-resizing


【解决方案1】:

要更改上传照片的质量,请尝试以下代码:

has_attached_file :img, 
              :styles          => { :thumb => '400x400#' },
              :convert_options => { :thumb => '-quality 80' }

您可以做的另一件事是多次创建具有不同大小的相同图像,然后调用您想要的图像大小。请参阅以下步骤:

  1. app/assets/images 中创建文件夹,使用指定所需质量的名称。例如,您可以拥有:app/assets/images/largeapp/assets/images/mediumapp/assets/images/thumb(您已经拥有这个)以及许多其他您想要的。
  2. 在具有附件的对象的模型中执行以下操作:

    has_attached_file :photo,
      styles: { original: "4000x4000>", large:"2000x2000>" ,medium:  "800x800>" ,thumb: "400x400>" },
      default_url: ":style/missing.png"
    
  3. 那么在你看来你可以这样做:

    <%= image_tag(yourObjectWithImgHere.img.url(:thumb) %>
    <%= image_tag(yourObjectWithImgHere.img.url(:medium) %>
    

您可以通过阅读this tutorial of thumbnail generation in the official wiki of paperclip 进一步了解转换选项或调整图像大小。 this question 也很有用。

【讨论】:

猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-10-12
  • 1970-01-01
  • 2016-09-01
  • 2015-08-03
  • 1970-01-01
相关资源
最近更新 更多