2012-10-02 52 views
1

我有一個Rails的圖片上傳下面的代碼:CarrierWave:從未經處理的圖像創建拇指

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 

基本上,我想兩兩件事:

  • 添加水印原始圖像
  • 創建原始圖像的縮略圖(沒有水印)

但是,它顯示爲雖然水印處理在創建縮略圖之前發生,但是有沒有辦法解決這個問題?

回答

0

原來,這是不可能的。對原始版本的任何處理都將影響所有versions

要做到這一點的唯一方法是保持原始版本清潔,並創建2個版本:version :thumbversion :watermarked