不同版本的不同文件扩展名

mir*_*ros 5 ruby carrierwave

我正在使用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
Run Code Online (Sandbox Code Playgroud)

当然,这也会改变我原始文件的扩展名.有什么方法可以解决这个问题吗?我想我需要覆盖版本块中的一些方法.但我无法弄清楚它们(我尝试重写文件名和网址,这有助于防止版本文件被删除).

Mar*_*sic 6

您可以像这样ovvierde每个版本使用的文件名:

 version :mobile do
   process :resize_to_limit => [72, 96]
   process :convert => "gif"
   def full_filename(for_file = model.logo.file)
     "fiename here"
   end
 end
Run Code Online (Sandbox Code Playgroud)

因此,只需保留原始文件名,然后根据需要更改它.维基上还有其他例子:

https://github.com/jnicklas/carrierwave/wiki/How-To%3A-Move-version-name-to-end-of-filename%2C-instead-of-front