PIL and font colour

J

Johny

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.
 
S

Steve Holden

Johny said:
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
 
P

python

Steve
Thank you for your reply.

Is there a way how to find out a complementary colour for an area where I will write the text, so
that the text will be seen clearly?Is there a routine in PIL or in Python somewhere?
Thank you for help

Lad.
 
S

Steve Holden

Steve
Thank you for your reply.

Is there a way how to find out a complementary colour for an area where I will write the text, so
that the text will be seen clearly?Is there a routine in PIL or in Python somewhere?
Thank you for help

Lad.
I see that you had an answer to this question on the PIL list, so I will
merely note that it's difficult if the background color turns out close
to mid-gray, or if it's very variable. In general this is a hard
problem. Are you sure it wouldn't be easier to just put a colored strip
behind the text and in front of the image?

regards
Steve
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,764
Messages
2,569,564
Members
45,039
Latest member
CasimiraVa

Latest Threads

Top