Plasticx Blog

Capable of being shaped or formed

Ruby RMagick Watermark Bug

Posted by Mike 01/12/2007 at 12:19AM

Here’s the quick and dirty on placing a shaded watermark bug on an image.

The result will be like this example with the bug in the lower right corner.

require 'RMagick'
if !ARGV[0]
    puts "Usage: wm <path-to-image>"
    exit
end
image = Magick::Image.read(ARGV[0]).first
mark = Magick::Image.read('wm.gif').first
mark = mark.shade(true, 310, 30)
image.composite!(mark, Magick::SouthEastGravity, Magick::HardLightCompositeOp)
out = ARGV[0].sub(/\./, "-wm.")
puts "Writing #{out}"
image.write(out)

Watermark image is a transparent gif:

Sample source image:

Check out RMagick’s indepth RMagick water marking page . My sample code modified one of their examples to specifically place a watermark in the lower right hand corner of the source image.

The ImageMagick commands to do the same actions at the command prompt are convert and composite


convert wm.gif -shade 310×30 shade.png
composite -gravity southeast -watermark 25 shade.png input.png output.png

Posted in |

Trackbacks<

Use the following link to trackback from your own site:
http://plasti.cx/trackbacks?article_id=220


Web Statistics