Place a Text with transparent background box onto a picture

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
OscarWilde
Posts: 1
Joined: 2014-06-16T07:28:15-07:00
Authentication code: 6789

Place a Text with transparent background box onto a picture

Post 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
Bonzo
Posts: 2971
Joined: 2006-05-20T08:08:19-07:00
Location: Cambridge, England

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

Post 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.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

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

Post 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
Post Reply