Carrierwave converting PDF to JPG (MiniMagick)

寵の児 提交于 2019-12-14 04:01:56

问题


I have a problem creating JPG thumbnails for PDF files.

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

Here is the code I use

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

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

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

I appreciate any suggestions / solutions.


回答1:


The problem was

process :quality => 95

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



来源:https://stackoverflow.com/questions/16036746/carrierwave-converting-pdf-to-jpg-minimagick

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!