I don't know of any published algorithm, but off the top of my head, I can think of two things.

Lets say the color you get it rgb(x,y,z) from IM where x,y,z are in the range 0-255 or 0-100%

1) you could make your text color the complement by replacing x->255-x, y->255-y, z->255-z
or likewise in percent.

or

2) you could take the color as a small swatch image and use -modulate 100,100,0 to rotate the hue by 180 degrees to get the complement color, then get its rgb values.

for example:

convert -size 1x1 xc:"rgb(79,148,205)" -modulate 100,100,0 -format "%[pixel:p{0,0}]" info:

returns

rgb(205,136,79)

and

convert -size 1x1 xc:"rgb(31%,58%,80%)" -modulate 100,100,0 -format "%[pixel:p{0,0}]" info:

returns:

rgb(80%,53.0007%,31.0002%)




Hello



I was wondering if anyone knows how to calculate a legible font-color,

once I've determined the mean color of the image (for a title bar).



I've experimented a bit with calculating the font color (white/black) for

when the title bar color is nearest a color in the 216 'safe' HTML color

table. But the result, though workable, to a degree, still leaves to be

desired, in that sometimes I really think the font color should be white

instead of black, and vice versa.



So, is there perhaps an algorithm out there I'm unaware of? Or a refined

lookup table of some sort.
_______________________________________________
Magick-users mailing list
[email protected]
http://studio.imagemagick.org/mailman/listinfo/magick-users

Reply via email to