Page 1 of 1
Multi-Color / Multi-Font Text
Posted: 2009-02-02T18:06:02-07:00
by extol
I would like to add multi-colored captions.
My text might be as follows on one picture ...
Rocky Mountains: Taken 10/12/2007
... and this way on the next one.
Dead Sea: Taken 11/11/2008
My problem is that, since my initial, red text, is of varying lengths, any scheme using compositing one image with one text color on top of a 2nd image with a 2nd text color is defeated by the fact that the x-position of the second text color text is determined by the width of the first text, which varies.
I hoped to just append them together, changing style information as I went ...
Any ideas?
Re: Multi-Color / Multi-Font Text
Posted: 2009-02-02T18:32:50-07:00
by fmw42
extol wrote:I would like to add multi-colored captions.
My text might be as follows on one picture ...
Rocky Mountains: Taken 10/12/2007
... and this way on the next one.
Dead Sea: Taken 11/11/2008
My problem is that, since my initial, red text, is of varying lengths, any scheme using compositing one image with one text color on top of a 2nd image with a 2nd text color is defeated by the fact that the x-position of the second text color text is determined by the width of the first text, which varies.
I hoped to just append them together, changing style information as I went ...
Any ideas?
This seems to work. See
http://www.imagemagick.org/Usage/text/
str1="Rocky Mountains"
str2=": "
str3="Taken 10/22/2007"
convert -background white \
\( -fill red -font Helvetica -pointsize 12 label:"$str1" \) \
\( -fill black -font Helvetica -pointsize 12 label:"$str2" \) \
\( -fill blue -font Helvetica -pointsize 12 label:"$str3" \) \
+append sometext.png
you can also set up string variables for the colors and the fonts
This is unix. If you are on windows, see
http://www.imagemagick.org/Usage/api/#windows
Re: Multi-Color / Multi-Font Text
Posted: 2009-02-02T19:40:48-07:00
by extol
fmw42 wrote:
This seems to work. See
http://www.imagemagick.org/Usage/text/
str1="Rocky Mountains"
str2=": "
str3="Taken 10/22/2007"
convert -background white \
\( -fill red -font Helvetica -pointsize 12 label:"$str1" \) \
\( -fill black -font Helvetica -pointsize 12 label:"$str2" \) \
\( -fill blue -font Helvetica -pointsize 12 label:"$str3" \) \
+append sometext.png
Thanks. However, in my effort to simplify my question, I neglected to give you all the requirements.
Let's go on to say that my text is not guaranteed to fit on a single line and still remain within the confines of my text-area. Currently I'm using the caption: command, with a -size 320x to force line-wraps. This works perfectly, but, as I said, I'd like to change colors and/or fonts in mid-caption.
Re: Multi-Color / Multi-Font Text
Posted: 2009-02-02T20:25:29-07:00
by fmw42
Sorry, I don't think you can easily have that degree of flexibility with IM. But perhaps Anthony or someone else can suggest something further.
Re: Multi-Color / Multi-Font Text
Posted: 2009-02-02T20:55:22-07:00
by anthony
If the font family and font size does not change simple appending will work fine.
But if the fonts and sizes change then you have to somehow align the 'baseline' of the text.
see IM Examples, Text handling, Creating Lines of Mixed Font Styles
http://www.imagemagick.org/Usage/text/#mixed_font_lines
for my examples of aligning wildly different image.
the alturnative is to extract font information for each string so you can calculate the next position of each bit of text. That is also a lot easier than it use to be!!!!
See from the same page, Determining Font metrics
http://www.imagemagick.org/Usage/text/#font_info
When you know how far the 'caret' moved for each font, then you can generate a much more accurate composite of different fonts.
Final suggestion (may not be practical). If you continue to work with the same font, Why not just annotate the whole string. then recolor sections of the image based on extracted or (or saved) string lengths.