Carrierwave在创建版本后存储原始文件

时间:2014-02-15 07:11:40

标签: ruby-on-rails ruby-on-rails-3 carrierwave

我有ImageUploader类,我希望在保存特定版本后保存原始图像的原始大小。帮我解决这个问题

上传

class ImageUploader < IconBase
 process :resize_to_fill => [490,68]

 version :normal do
  process resize_to_fill: [245,34]
  def full_filename(for_file = model.logo.file)
    "avatar1.png"
  end
 end

 def filename
   "avatar.png"
 end
end

1 个答案:

答案 0 :(得分:4)

您的原始尺寸未保存,因为您的上传器中有process :resize_to_fill => [490,68]。要保持原始大小,您可以将其放入另一个版本,这样您的主图像将保持未处理状态,如下所示:

version :large do
  process :resize_to_fill => [490,68]
end

然后你会:

uploader.url        # original image
uploader.large.url  # [490,68] version
uploader.normal.url # [245,34] version