【问题标题】:Carrierwave converting PDF to JPG (MiniMagick)Carrierwave 将 PDF 转换为 JPG (MiniMagick)
【发布时间】:2013-04-16 12:11:38
【问题描述】:

我在为 PDF 文件创建 JPG 缩略图时遇到问题。

我正在使用 Carrierwave。 Imagemagick 已正确安装。创建 PNG、JPG 或 GIF 文件的缩略图没有问题。

这是我使用的代码

version :thumb, :if => :image? do
    storage :file

        begin
            process :convert => 'jpg' # this should do the trick but doesn't
            process :resize_to_fill => [160,160]
            process :quality => 95
            process :set_content_type
            process :set_thumb_attr => true
            def full_filename (for_file = model.file.file) 
                "#{model.slug}-thumb.jpg" 
            end
        rescue Exception => e
            puts e.inspect
            true
        end
end

def set_thumb_attr(val)
    model.thumb = val
end


def image?(new_file)
    model.mime.include? 'image/' or model.mime.include? '/pdf'
end

def set_content_type(*args)
    self.file.instance_variable_set(:@content_type, "image/jepg")
end

缩略图的内容表明创建的文件仍然是 PDF 文件。

%PDF-1.3 1 0 对象

感谢任何建议/解决方案。

【问题讨论】:

    标签: ruby-on-rails carrierwave minimagick


    【解决方案1】:

    问题是

    process :quality => 95
    

    它重新处理了 PDF。删除该行解决了我的问题。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2020-03-26
      • 1970-01-01
      • 2015-11-05
      • 1970-01-01
      • 2019-05-29
      • 2014-02-02
      • 2013-12-26
      相关资源
      最近更新 更多