Image watermarking with CarrierWave

I love the library for handling image uploads. But how can we do watermarks?

Easy. Prepare a transparent PNG with your logo, then add the following rule to your Uploader class:

  def watermark(path_to_file)
    manipulate! do |img|
      logo = Magick::Image.read(path_to_file).first
      img = img.composite(logo, Magick::SouthEastGravity, Magick::OverCompositeOp)
    end
  end

Now call it like this:

  version :medium do
    process :resize_to_fill => [500,500]
    process :watermark => ["#{RAILS_ROOT}/public/images/logo.png"]
  end

Bingo, a beautiful watermark.

Tags: , ,

Leave a Reply