isLightColor
Back to ListDescription: Calculate if color is light or dark
FileMaker Prototype:
Set Variable [$res; ACF_Run("isLightColor"; string_hex)]
Category: UTILITY
Dependencies
- Hex2Dec: Convert hex value to decimal
Function source:
function isLightColor ( string hex )
int r,g,b;
hex = regex_replace ( "[^0-9A-F]", upper(hex), "");
// calc r, g, and b decimal values.
r = Hex2Dec(substring(hex,0,2));
g = Hex2Dec(substring(hex,2,2));
b = Hex2Dec(substring(hex,4,2));
// Calculate colour luminance
float lum = 0.299 * r + 0.587 * g + 0.114 * b ;
return (lum > 128.0); //
end
The isLightColor Function calculates if a color is light according to its RGB input. Use Hex values, 6 digits.
Example
Set Variable [$res; ACF_Run("isLightColor"; "#7962a8")]
Result: False because it calculates to luminance = 112, means is less than 128 that is the threshold.
The function is rewritten from colorContrast ( color ) found on Brian Dunnings Custom Functions site. It says on the web page that it returns "1", but I have tested it with the given parameter, and this also returns "0" with this given value.
We have made a general Hex to Decimal function that also can be of general use.
Set Variable [$res; ACF_Run("Hex2Dec"; string_hex)] 