我正在使用载波上传图片。我需要我的主图像版本 保留其原始格式,但要转换其他版本 到 gif。
目前我正在做这样的事情:
def filename
change_ext_to_gif(super)
end
def change_ext_to_gif(ext)
ext.chomp(File.extname(ext)) + ".gif"
end
version :preview do
process :resize_to_fill => [60, 60]
process :convert => "gif"
end
version :full do
process :resize_to_limit => [320, 320]
process :convert => "gif"
end
version :mobile do
process :resize_to_limit => [72, 96]
process :convert => "gif"
end
当然,这也改变了我原始文件的扩展名。是 有什么办法可以解决这个问题?我想我需要重写一些方法 在版本的 block 中。但是我无法弄清楚它们(我 尝试覆盖文件名和 url 这有助于但会阻止版本 文件被删除)。
最佳答案
您可以像这样跳过每个版本使用的文件名:
version :mobile do
process :resize_to_limit => [72, 96]
process :convert => "gif"
def full_filename(for_file = model.logo.file)
"fiename here"
end
end
因此,只需保留您喜欢的原始文件名,然后根据版本进行更改。这里的 wiki 上还有更多示例:
关于ruby - 不同版本的不同文件扩展名,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5292113/