Thanks.

I already tried inverting the colors before, but that didn't work out all
that well. The modulate example also yield not too good results. On the
example you gave, the blue-ish background gets a sort of light-brown font
that, though visible, still does not look optimal (white would be, in that
case). Though modulate is definitely a step up from just inverting. :)

I guess this is just harder than I thought it would be. I'm sure there's a
logic to the human eye as to what colors go well together, but I haven't
figured it out yet. :) What you'd really need is a predefined table, with
a somewhat larger granularity than the table with 216 'safe' colors I
found. 

- Mark


-----Original Message-----
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On Behalf Of Fred Weinhaus
Sent: zondag 13 april 2008 0:12
To: [email protected]
Subject: [magick-users] Automagically determining font-color


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

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

Reply via email to