加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

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

发布时间:2020-12-17 03:19:54 所属栏目:百科 来源:网络整理
导读:我正在使用carrierwave上传图片.我需要我的主要图像版本 保持原始格式,但要转换的其他版本 到gif. 目前我正在做这样的事情: def filename change_ext_to_gif(super) end def change_ext_to_gif(ext) ext.chomp(File.extname(ext)) + ".gif" end version :pr
我正在使用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

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

解决方法

您可以像这样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

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

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

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读