【发布时间】:2015-05-26 09:55:31
【问题描述】:
用户可以上传图片或 PDF。我想显示一个小缩略图(PDF 的第一页)
此代码适用于图像,但不适用于 PDF。
version :thumb, :if => :image? do
process :resize_to_limit => [80, 80]
end
version :thumb, :if => :pdf? do
process :cover
process :resize_to_fill => [80, 80]
process :convert => :jpg
def full_filename (for_file = model.source.file)
super.chomp(File.extname(super)) + '.jpg'
end
end
def cover
manipulate! do |frame, index|
frame if index.zero?
end
end
protected
def image?(new_file)
new_file.content_type.start_with? 'image'
end
def pdf?(new_file)
new_file.content_type.end_with? 'pdf'
end
【问题讨论】:
标签: ruby-on-rails carrierwave rmagick