Page 1 of 1

Write Content within Transparent Box

Posted: 2014-12-26T13:03:44-07:00
by lawguy
xecutive Overview:

I have a picture called funny-santa.jpg (Google Image it, it is cute)
I have been able to draw a yellow box ONTO funny-santa.jpg'
I am able to put TEXT into that yellow box.("Merry Christmas Mom and Dad")
How do I auto fit text within yellow box i created - Programatically?
Is it possible to auto-fit the below text to a pre-defined space?

-- End

Dear Friends,

Here is the code to draw a TRANSPARENT Yellow box onto an existing picture. I have added the text 'Merry Xmas Mom and Dad" within the document. The challange is this: How do I auto-fit my 'Merry Xmas Mom and Dad' within the Box I just created?

What if my text were to change to "I love You Mom and Dad". Any 'hard-coded values' based on text dimension would have to be redone.

convert funny-santa.jpg -strokewidth 0 -fill "rgba( 255, 215, 0 , 0.5 )" -draw "rectangle 0,0 1024,350" -pointsize 30 -fill black -annotate +67+60 'Merry Christmas Mom and Dad' output.jpg

Re: Write Content within Transparent Box

Posted: 2014-12-26T13:13:31-07:00
by lawguy
Hey Friends,

I spent all Xmas, and the day after trying to get this to work. This shouldn't be this hard?! I must be a moron.

All I want is to draw a YELLOWBOX transparent box with text over an existing picture. Ideally I would like the words to FIT? Maybe this is beyond the scope of this product. SAD FACE

Re: Write Content within Transparent Box

Posted: 2014-12-26T13:16:12-07:00
by fmw42
To autofit, you need to use label: or caption: and create a transparent background image of the width desired with the opaque text you want. Then compose that image over your background image where you would like the text to show. See

http://www.imagemagick.org/Usage/text/
http://www.imagemagick.org/Usage/text/#label
http://www.imagemagick.org/Usage/layers/#convert

If you want the text to be in yellow border, then use -bordercolor ... -border to add that to the transparent text image before the compose step. See

http://www.imagemagick.org/Usage/crop/#border

In the future, please always identify your version of IM and platform as syntax may be different and older versions of IM may have bugs or be too old for certain features.

Re: Write Content within Transparent Box

Posted: 2014-12-26T13:30:01-07:00
by fmw42
try

(unix syntax) (reduce -size 1024x if you want the text to be smaller and re-adjust the positioning with -geometry

Code: Select all

convert funny_santa.jpg \
\( -size 1024x -background "rgba(255,215,0,0.5)" label:"Merry Christmas Mom and Dad" \) \
-geometry +67+60 -compose over -composite result.jpg
(windows syntax)

Code: Select all

convert funny_santa.jpg ^
( -size 1024x -background "rgba(255,215,0,0.5)" label:"Merry Christmas Mom and Dad" ) ^
-geometry +67+60 -compose over -composite result.jpg
Note generally better to keep spaces out of rgb colors, but as long as you put quotes around them it should be fine anyway.

Re: Write Content within Transparent Box

Posted: 2014-12-26T14:03:24-07:00
by lawguy
Dear Fmw42:

You are absolutely amazing. Moreover, you also answered this question right when I got my answer as well. Here is what I came up with.

vic@ubuntu:~/top_10$ convert -size 1024x300 -background rgba\(0,255,255,0.25\) -fill black -gravity center caption:'Merry Xmas Mom' cap.png
vic@ubuntu:~/top_10$ composite -geometry +0+0 cap.png funny-santa.jpg funny-santa-vic.jpg

Re: Write Content within Transparent Box

Posted: 2014-12-26T15:21:50-07:00
by fmw42
Composite is old and one should learn to use convert in its place. Convert has more flexibility and you can do it all in one command line.