Apply watermark with text / image using GraphicsMagick

Giannis picture Giannis · Jan 8, 2014 · Viewed 9.1k times · Source

I need to be able to apply watermark on an image, using either text or another image. Getting it to work with an image was quite straight forward, using the following command:

gm composite -dissolve 15 -tile logo.png image.jpg wmark_tiled.jpg

Now, I also want to be able to use text for watermarking (in other cases). The only thing that I found close to it, is a command from ImageMagick tutorial which is the following :

convert -size 140x80 xc:none -fill grey -gravity NorthWest -draw "text 10,10 'copyrigh text'" -gravity SouthEast -draw "text 5,15 'copyright text'" miff:- | gm composite -tile - image.jpg copyrightImage.jpg 

Although its not working in GM, and I would rather avoid using pipe as it causes some headaches managing it from Java.

What I thought I could do, is generate an image from a given text, and then use that image as logo.png is used on my first command. Although I cannot find how to generate an image out of text, all I find is putting text on top of an image.

Ideally I will generate a transparent image with the text, and from what I see modifying font/color etc should be quite flexible.

Any suggestions on how to achieve this, or any better solutions are welcome. (I added imagemagick tag as the interfaces are often same/similar)

Answer

Moogle picture Moogle · Jan 8, 2014

I'm not sure I fully understand your query, so apologies if I've misunderstood, but are you trying to create a transparent image, with some text in the corner? If so, would this not work?

convert -background transparent -fill grey -font Calibri -size 140x80 -pointsize 14 -gravity southeast label:'copyright text' output.png

Obviously adjusting the font, pointsize, output image name etc. That would create the following:

http://oi42.tinypic.com/14j1bvp.jpg

P.S. that was written for ImageMagick. I don't know how GM differs or whether it would still work.