Watermark with ImageMagick and Ruby

20 Sep 2010

require 'RMagick'

if ARGV.length != 2
    puts "Usage: ruby rwatermark.rb <path-to-watermark> <path-to-image>"
    exit
end

open image file

image = Magick::Image.read(ARGV[1]).first

add watermark

mark = Magick::Image.read(ARGV[0]).first
mark.change_geometry('240x120') { |cols, rows, img|
img.resize!(cols, rows)
}
image.composite!(mark, Magick::SouthEastGravity, Magick::DissolveCompositeOp)

save watermarked file

out = ARGV[0].sub(/\./, "-wm.")
puts "Writing #{out}"
image.write(out)