问题
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