[Image-SIG] Font colour

Christopher Barker Chris.Barker at noaa.gov
Wed Apr 25 21:42:27 CEST 2007

export at hope.cz wrote:

> Is there a way how to set the font colour so that it will be seen very 
> clearly in the picture?

One way to do this in general is to put a background color behind the 
font. I don't see a way to do this automatically with PIL, but you can 
get the size of the text:

font.getsize(text) => (width, height)

Then draw a rectangle of that size before you draws the text. If you 
(for example) draw a white rectangle, then black text, you will be able 
to see that on top of any color.

The option is to get fancy with determining the average color of th 
region where the text goes, then create a color that contrasts with 
that. However, if your text overlaps two (or more) regions of very 
different colors, it may be hard to automatically get a color that 
contrasts with all of them.


Christopher Barker, Ph.D.

Emergency Response Division
NOAA/NOS/OR&R            (206) 526-6959   voice
7600 Sand Point Way NE   (206) 526-6329   fax
Seattle, WA  98115       (206) 526-6317   main reception

Chris.Barker at noaa.gov

More information about the Image-SIG mailing list