不同版本有不同的文件扩展名
我正在使用 Carrierwave 上传图像。我需要我的主图像版本 保留其原始格式,但要转换其他版本 到 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
当然,这也会更改我的原始文件的扩展名。是 有什么办法解决这个问题吗?我想我需要重写一些方法 在版本的块中。但我无法弄清楚它们(我 尝试覆盖文件名和网址,这有帮助,但会阻止版本 文件被删除)。
I am using carrierwave to upload images. I need my main image version
to remain in its original format, but other versions to be converted
to gif.
At the moment i am doing something like this:
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
Of course, this changes extension of my original file as well. Is
there any way to solve this? I guess i need to override some methods
in the version's blocks. But i was not able to figure out them (I
tried overriding filename and url this helps but prevents version`s
files from being deleted).
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以像这样修改每个版本使用的文件名:
因此,只需保留原始文件名,然后按版本更改它即可。维基百科上还有更多示例:
https://github.com/jnicklas/rierwave/wiki/How-To%3A-Move-version-name-to-end-of-filename%2C-instead-of-front
You can ovvierde the filename that gets used per version like so:
So just leave the original filename as you'd like and then alter it per version. There are further examples on the wiki here:
https://github.com/jnicklas/carrierwave/wiki/How-To%3A-Move-version-name-to-end-of-filename%2C-instead-of-front