我有一个问题,为PDF文件创建JPG缩略图。
我在用载波。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 10 << /Pages 2 0 R /Type /Catalog .
我感谢任何建议/解决方案。
发布于 2013-04-16 17:25:46
问题是
process :quality => 95它重新处理了PDF文件。删除那条线解决了我的问题。
https://stackoverflow.com/questions/16036746
复制相似问题