Differently colored annotations

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
bourbaki
Posts: 2
Joined: 2016-04-14T03:38:38-07:00
Authentication code: 1151

Differently colored annotations

Post 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.
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Differently colored annotations

Post 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.
snibgo's IM pages: im.snibgo.com
User avatar
GeeMack
Posts: 718
Joined: 2015-12-01T22:09:46-07:00
Authentication code: 1151
Location: Central Illinois, USA

Re: Differently colored annotations

Post 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.
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Differently colored annotations

Post 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
snibgo's IM pages: im.snibgo.com
bourbaki
Posts: 2
Joined: 2016-04-14T03:38:38-07:00
Authentication code: 1151

Re: Differently colored annotations

Post by bourbaki »

Thanks a lot for your answers, which help me a lot.
Great forum, great support, great software.
Post Reply