Page 1 of 1

Adding an image to the end of text

Posted: 2008-05-28T08:51:56-07:00
by riegel
How would I determine the width and height of the text I am creating so that I can place an image based on that width and height.

Re: Adding an image to the end of text

Posted: 2008-05-28T09:28:38-07:00
by fmw42
I am not sure I know exactly what you mean, but I have used a two step process for creating text. First use label: to build the text, then get the dimensions, then redo with -annotate.

convert -background $bc \
-fill $tc $stroke -font $font -pointsize $point \
-gravity center label:"$text" \
-trim -bordercolor "$bc" -border 10 +repage $tmp0
wd=`identify -format %w $tmp0`
ht=`identify -format %h $tmp0`
dim="${wd}x${ht}"


convert -size $dim xc:"$bc" $fill \
$stroke -undercolor $uc \
-font $font -pointsize $point \
-gravity center -annotate 0x${italic}+0+0 "$text" \
-trim -bordercolor $bc -border $linewt +repage $tmp0

Re: Adding an image to the end of text

Posted: 2008-05-28T09:35:05-07:00
by riegel
Thanks for the reply. I was trying to avoid multiple steps and was looking for a one liner. I may need to do what you have suggested.

I think I am onto a solution. Here is what I have so far. Basically I create my text then apply a -trim then I do a +composite using gravity and geometry.

The problem I am having is the resulting image is cropped. Is there a way after applying a -trim to an image to them add space around it?

Re: Adding an image to the end of text

Posted: 2008-05-28T10:57:46-07:00
by fmw42
see my example. I add a generous border, then trim it later as needed after the text is added (centered) and then add whatever final border is desired. See -border in the IM docs.