【问题标题】:Carrierwave store original file after creating the versionCarrierwave 在创建版本后存储原始文件
【发布时间】:2014-02-15 16:50:16
【问题描述】:

我有 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

【问题讨论】:

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


    【解决方案1】:

    您的原始大小未保存,因为您的上传器中有process :resize_to_fill =&gt; [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
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2018-12-05
      • 1970-01-01
      • 2012-08-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多