You are here

function textimage_match_luma in Textimage 7.3

Determine best match to over/underlay a defined color.

Calculates UCCIR 601 luma of the entered color and returns a black or white color to ensure readibility.

See also

http://en.wikipedia.org/wiki/Luma_video

4 calls to textimage_match_luma()
theme_textimage_colored_string in ./textimage.module
Render a text string, color formatted.
_textimage_draw_box in effects/textimage_text.inc
Draw a box.
_textimage_draw_debug_box in effects/textimage_text.inc
Display a polygon enclosing the text line, and conspicuous points.
_textimage_draw_rectangle in effects/textimage_text.inc
Draw a rectangle.

File

./textimage.module, line 1021
Textimage - Provides text to image manipulations.

Code

function textimage_match_luma($rgba, $soft = FALSE) {
  list($r, $g, $b) = array_values(imagecache_actions_hex2rgba($rgba));
  $luma = 1 - (0.299 * $r + 0.587 * $g + 0.114 * $b) / 255;
  if ($luma < 0.5) {

    // Bright colors - black.
    $d = 0;
  }
  else {

    // Dark colors - white.
    $d = 255;
  }
  return _color_pack(array(
    $d,
    $d,
    $d,
  ));
}