PIL and font colour
Steve Holden
steve at holdenweb.com
Wed Apr 25 10:17:15 EDT 2007
Johny wrote:
> I use PIL to write some text to a picture.The text must be seen wery
> clearly.
> I write the text to different pictures but to the same position. As
> pictures maybe different, colour, in the position where I write the
> text, is also different.
> Is there a way how to set the font colour so that it will be seen very
> clearly in the picture?
> For example, if the picture is bright ( for example yellow), the font
> colour should be dark( e.g. black) and vice versa.
> Can anyone help?
> Thanks
> L.
>
The easy way to ensure this is to paint a background rectangle of an
appropriate color to ensure good font contrast before writing the text.
Of course, this obscures rather more of the image in the background than
you might otherwise.
Apart from that you could try averaging the pixel values in the area you
are going to paint on, and then choose a font color that contrasts well
with the average. If there are large variations in color, however, this
can give disappointing results.
If you'd like to get some insight into color contrast you could do worse
than start at
http://wellstyled.com/tools/colorscheme2/index-en.html
regards
Steve
--
Steve Holden +1 571 484 6266 +1 800 494 3119
Holden Web LLC/Ltd http://www.holdenweb.com
Skype: holdenweb http://del.icio.us/steve.holden
Recent Ramblings http://holdenweb.blogspot.com
More information about the Python-list
mailing list