Search code examples
ruby-on-railsruby-on-rails-3ruby-on-rails-3.1carrierwavermagick

Carrierwave add a watermark to processed images


Im trying to add a watermark to processed images with below code I got from several resources:

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

Only problem is, you guess it, does not work. I get no errors in log/console whatsoever

This is my method inside my uploaded and called like:

def function
  version :thumb do
    process :resize_to_fill => [96, 96]
    process :watermark
  end
end

Any thoughts on getting some logs on why this doesn't work? I have the Rmagick gems and Imagemagick installed on my system (OSX) And resizing of images does work correct.


Solution

  • I just do it this way and it works very fine:

    # Process files as they are uploaded:
    process :resize_to_fill => [850, 315]
    process :convert => 'png'
    process :watermark
    
    def watermark
      manipulate! do |img|
        logo = Magick::Image.read("#{Rails.root}/app/assets/images/watermark.png").first
        img = img.composite(logo, Magick::NorthWestGravity, 15, 0, Magick::OverCompositeOp)
      end
    end
    

    B.