Adding an image to the end of text

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
riegel
Posts: 26
Joined: 2003-08-19T12:36:46-07:00
Location: Rocky Mount, NC 27804

Adding an image to the end of text

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

Re: Adding an image to the end of text

Post 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
riegel
Posts: 26
Joined: 2003-08-19T12:36:46-07:00
Location: Rocky Mount, NC 27804

Re: Adding an image to the end of text

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

Re: Adding an image to the end of text

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