【问题标题】:Using convert options for ImageMagick in rails在 Rails 中使用 ImageMagick 的转换选项
【发布时间】:2016-02-11 05:16:56
【问题描述】:

正在处理一个允许将上传的 pdf 转换为 png 的项目。到目前为止,这是我所得到的:

 class MyModel < ActiveRecord::Base

          has_attached_file :attachment1, 
             styles: { image: ["1125x1500", :png] }, 
             default_url: "/images/missing.png", 
             :convert_options => { density: "1050", quality: "1050" }

{other stuff}
end

convert_options 似乎不起作用,因为调整密度和质量似乎不会对图像产生任何影响。我担心我在这里没有使用正确的语法。

【问题讨论】:

    标签: ruby-on-rails imagemagick imagemagick-convert


    【解决方案1】:

    convert_options以key为图片样式,value为options字符串:

    class MyModel < ActiveRecord::Base
      has_attached_file :attachment1, 
         styles: { image: ["1125x1500", :png] }, 
         default_url: "/images/missing.png", 
         :convert_options => { image: "-density 1050 -quality 1050" }
    
      {other stuff}
    end
    

    【讨论】:

    • 注意:我假设您知道这里的质量水平是荒谬的,只是保持示例一致。质量应该是 1-100
    猜你喜欢
    • 2011-05-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-02-14
    • 1970-01-01
    • 2012-11-30
    • 1970-01-01
    • 2023-02-26
    相关资源
    最近更新 更多