【问题标题】:Image resize issue with PaperClip and Rails 3PaperClip 和 Rails 3 的图像调整大小问题
【发布时间】:2013-02-06 08:26:47
【问题描述】:

自从升级到 Ruby 1.9.3、Rails 3.1.0.rc4 和 Paperclip 3.4.0 后,我的应用程序图像渲染出现了严重问题。

无论我为 Paperclip 提供何种设置变化,下面链接的 infile 都会出现模糊,如链接的 outfile 所示。

outfile 必须适合 620x412 as shown here 的框。

Link to input file

Link to output file this code generates

模型的完整代码如下...

class Propertyimage < ActiveRecord::Base

  belongs_to :property

  validates_presence_of :description
  validates_presence_of :sortorder

  has_attached_file :image, :styles => { :export => {:geometry => "620x412#", :quality =>    100, :format => 'JPG'} },
  :path => ":rails_root/public/system/:attachment/:id/:style/:filename",
  :url => "/system/:attachment/:id/:style/:filename"
end

【问题讨论】:

    标签: ruby-on-rails-3 imagemagick paperclip ruby-1.9.3


    【解决方案1】:

    我遇到了类似的问题,经过大量试验和错误后,我能够使用以下三个标准进行修复:图像尺寸规范、convert_options 和缩放图像。例如,在您的 Propertyimage 类中尝试:

    has_attached_file :image, 
      :styles => { :original => ["640x480", :jpg], :export => {:geometry => "620x412#", :quality => 100, :format => 'JPG'} },
      :convert_options => { :all => "-quality 100" },
      :path => ":rails_root/public/system/:attachment/:id/:style/:filename",
      :url => "/system/:attachment/:id/:style/:filename"
    

    然后您可以使用图像标签的大小,或者在我使用 PDF 的情况下,Id 使用缩放选项:

    pdf.image the_file_name, :at => [0, 720], :scale => 0.75
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-11-10
      • 2017-12-09
      • 1970-01-01
      • 2011-07-04
      • 1970-01-01
      • 2012-10-17
      相关资源
      最近更新 更多