CarrierWave:从未处理的图像创建拇指

时间:2012-10-02 20:10:38

标签: ruby-on-rails-3 carrierwave

我有一个Rails图像上传器的代码:

class PhotoUploader < BaseUploader
  ...

  # Create different versions of your uploaded files:
  version :thumb do
    process :resize_to_fill => [80, 80]
  end

  # Process files as they are uploaded:
  process resize_to_fit: [618, 412]
  process convert: 'png'
  process :watermark
  process convert: 'jpg'

  def watermark
    manipulate! do |img|
      logo = Magick::Image.read("#{Rails.root}/app/assets/images/watermark.png").first
      img = img.composite(logo, Magick::NorthEastGravity, 0, 20, Magick::OverCompositeOp)
    end
  end

end

基本上,我想要两件事:

  • 在原始图像上添加水印
  • 创建原始图像的缩略图(不带水印)

然而,好像水印处理在创建缩略图之前就已经发生了,有什么方法吗?

1 个答案:

答案 0 :(得分:0)

事实证明这是不可能的。对原始版本的任何处理都将影响所有versions

唯一的方法是保持原始版本的清洁并从中创建2个版本:version :thumbversion :watermarked