Never been to DZone Snippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

Watermarking your images with RMagick (See related posts)

Source: RMagick - Watermarking Images With the shade Method [rubyforge.org]

require 'RMagick'

if !ARGV[0]
    puts "Usage: watermark <path-to-image>"
    exit
end

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

mark = Magick::Image.new(image.columns, image.rows)

gc = Magick::Draw.new
gc.gravity = Magick::CenterGravity
gc.pointsize = 32
gc.font_family = "Helvetica"
gc.font_weight = Magick::BoldWeight
gc.stroke = 'none'
gc.annotate(mark, 0, 0, 0, 0, "Watermark\nby\nRMagick")

mark = mark.shade(true, 310, 30)

image.composite!(mark, Magick::CenterGravity, Magick::HardLightCompositeOp)

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


Have a look at the sample output complete with watermark [twitxr.com]

Comments on this post

Stone posts on Sep 09, 2009 at 13:05
nice code i like the way you are working and making things easy, one of my friend who is doing business of cheap vps services told me about your site to consult some codes and i love to be here again and again, this time i was here when i was looking some cheap packages of managed dedicated hosting services along with cheap packages of asp net hosting services, which are best to use at home or office, i will be here again as i get some time because you are doing really nice job. thanks for sharing nice stuff with us.

You need to create an account or log in to post comments to this site.


Click here to browse all 7308 code snippets

Related Posts