Programmatically determine the average greyscale

J. Landman Gay jacque at
Thu Feb 18 21:27:14 EST 2016

On 2/18/2016 5:05 PM, Sannyasin Brahmanathaswami wrote:
> But if I use white type on top of the image and the sky appears there
> in the top left area of the image is a light color, then we have a
> problem with contrast/readability.
> Is there a way to get the "average" grayscale value of a small area
> of a photo?

I'm not sure about getting an average, but someone posted the following 
handler here a while ago. I'm sorry I can't give credit, I should have 
saved that.

Determine whether to show white or black text against a colored background:

function calcLuminance pRGB
   -- wikipedia: Y = 0.2126 R + 0.7152 G + 0.0722 B
   put item 1 of pRGB * 0.2126 into tR
   put item 2 of pRGB * 0.7152 into tG
   put item 3 of pRGB * 0.0722 into tB
   if sum(tR,tG,tB) > 125 then return "black"
   else return "white"
end calcLuminance

Jacqueline Landman Gay         |     jacque at
HyperActive Software           |

More information about the use-livecode mailing list