@RGBLUM
— Returns a
luminance value for a color.
Syntax:
%@RGBLUM[
color]
color | may be specified as # rrggbb or as a W3C color name. |
If you specify the color in hexadecimal with a
leading #
sign, it must be either three or six hex digits long.
If it’s three digits long, each digit is doubled; #8ac
is the
same as #88aacc
. Alternatively, you can use a leading 0x
and the rules above do not apply; the number of digits is not significant.
A luminance value from 0 (darkest) to 1000 (brightest) is returned. You can use this to pick a contrasting color. For example, if a background has a luminance of less than 500, white would make a good contrasting color for text; if it’s at least 500, then black would be a better choice.
The three color channels are given different weights: green is 58.7% of the luminance value, red is 29.9%, and blue is 11.4%.
rem Is yellow bright or dark?
if %@rgblum[yellow] ge 500 ( echo It's bright! ) else ( echo It's dark! )
See also: the _BGCOLOR
variable, which returns the current background color; and the
@IMGCOLOR
function, which returns a color
from a graphics file.