Page 1 of 1

Place a Text with transparent background box onto a picture

Posted: 2014-06-16T08:18:47-07:00
by OscarWilde
I've played around with IM the whole day but I'm not able to place a

Code: Select all

convert -font /font/arial.ttf -pointsize 42 -background \"#0008\" -fill white label:\"This is my label!\" input.jpg +swap -gravity SouthEast -composite output.jpg
This is the Result:
Image
But what I need is this:
Image

I have no Idea how to do this? Can anyone give me some help?

Frank

Re: Place a Text with transparent background box onto a pict

Posted: 2014-06-16T09:01:18-07:00
by Bonzo
Try this:

Code: Select all

convert ( -size 500x50 xc:rgba(255,255,8,0.5) -font /font/arial.ttf -fill rgba(0,0,0,1) -pointsize 42 -gravity center -annotate +0+0 "This is my label!" ) input.jpg +swap -gravity SouthEast -geometry +0+20 -composite output.jpg
This creates a canvas first using a semi transparent rgb colour; the brackets hold this information together - might work without but it is easier to see what is happening.
The -geometry moves the watermark up from the bottom by 20 pixels.
I belive label fits the background to the text and that is why I made a canvas first; so you can have some space around the text. This can have complications if your text size changes.

Imagemagick has so many options it can be hard to work things out until you start to see how it works. You can check out Anthony's examples and I have a few on my site using php.

Re: Place a Text with transparent background box onto a pict

Posted: 2014-06-16T10:18:53-07:00
by fmw42
This works for me on Unix. User your background color to specify half transparent yellow.

convert -font /font/arial.ttf -pointsize 42 -background "rgba(255,255,0,0.5)" -fill white label:"This is my label\!" input.jpg +swap -gravity SouthEast -composite output.jpg

or in hex colors

convert -font /font/arial.ttf -pointsize 42 -background "#ffff0088" -fill white label:"This is my label\!" input.jpg +swap -gravity SouthEast -composite output.jpg

You can add -geometry to offset the position from the bottom right corner if you want. see
http://www.imagemagick.org/script/comma ... p#geometry
http://www.imagemagick.org/Usage/layers/#convert