载波将PDF转换为JPG(MiniMagick) [英] Carrierwave converting PDF to JPG (MiniMagick)

查看:84
本文介绍了载波将PDF转换为JPG(MiniMagick)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I have a problem creating JPG thumbnails for PDF files.

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

I'm using Carrierwave. Imagemagick is properly installed. There are no problems creating thumbnails of PNG, JPG or GIF files.

这是我使用的代码

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文件。

The content of the thumbnail suggests that the created file is still a PDF-file.


%PDF-1.3
1 0 obj
<<
/页2 0 R
/类型/目录
...

%PDF-1.3 1 0 obj << /Pages 2 0 R /Type /Catalog ...

我很感谢建议/解决方案。

I appreciate any suggestions / solutions.

推荐答案

问题是

process :quality => 95

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

It reprocessed the PDF. Removing that line resolved my problem.

这篇关于载波将PDF转换为JPG(MiniMagick)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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