Page 1 of 1

Differently colored annotations

Posted: 2016-04-14T03:42:12-07:00
by bourbaki
Hello everybody out there using ImageMagick,

Is it possible to have an annotation with 1 part in green followed by another one in red?
The spacing of letters should not be affected as when using the +x+y attribute.

Thanks in advance for your help.

Re: Differently colored annotations

Posted: 2016-04-14T05:31:04-07:00
by snibgo
I don't know exactly what you want. See http://www.imagemagick.org/Usage/annotating/ for many examples. If that doesn't help, show an example of what you want to do.

Re: Differently colored annotations

Posted: 2016-04-14T07:21:10-07:00
by GeeMack
bourbaki wrote:Is it possible to have an annotation with 1 part in green followed by another one in red?
The spacing of letters should not be affected as when using the +x+y attribute.
Using "ImageMagick 6.9.3-6 Q16 x64" I've achieved varying degrees of success using some of the following. Here's an idea using "label"...

Code: Select all

convert ^
   -gravity northwest ^
   -pointsize 48 ^
   -fill black ^
   label:"The blue word." ^
   -fill blue ^
   label:"The blue" ^
   -fill black ^
   label:"The" ^
   -layers merge ^
   -size 600x100 ^
   canvas:white ^
   +swap ^
   -gravity center ^
   -composite ^
      output1.png
Here's a way to do it using "annotate"...

Code: Select all

convert ^
   -size 600x100 ^
   canvas:white ^
   -gravity northwest ^
   -pointsize 48 ^
   -fill black ^
   -annotate +0+0 "The blue word." ^
   -fill blue ^
   -annotate +0+0 "The blue" ^
   -fill black ^
   -annotate +0+0 "The" ^
      output2.png
And another idea using "pango"...

Code: Select all

convert ^
   -size 600x100 ^
   -gravity center ^
   -pointsize 48 ^
   pango:"The <span foreground='blue'>blue</span> word." ^
      output3.png
I'm not fully satisfied with any of these methods. A tiny bit of the previous color might show around the edges with the "label" or "annotate" methods. The location on the page can be a little flaky depending on the font. Even using certain mono-spaced fonts there seems to be a lack of predictability. If I had any amount of multi-color text to create, I'd probably do it in a word processor and save it as a PDF, then extract it and composite it with ImageMagick for the final work.

Re: Differently colored annotations

Posted: 2016-04-14T07:48:49-07:00
by snibgo
Another method for GeeMack's "The blue word" is to make a label of each word (plus trailing space), and "+append".

Code: Select all

%IM%convert ^
   -pointsize 48 ^
   -fill black ^
   label:"The " ^
   -fill blue ^
   label:"blue " ^
   -fill black ^
   label:"word." ^
   +append ^
      output4.png

Re: Differently colored annotations

Posted: 2016-04-15T05:12:38-07:00
by bourbaki
Thanks a lot for your answers, which help me a lot.
Great forum, great support, great software.