You are here

function _textimage_hex2rgb in Textimage 5

Same name and namespace in other branches
  1. 5.2 textimage.module \_textimage_hex2rgb()
  2. 6.2 textimage.module \_textimage_hex2rgb()
  3. 7.2 textimage.utils.inc \_textimage_hex2rgb()

Convert a hex string to it's rgb integer components $hex can be in the formats: '#ABC','ABC','#AABBCC','AABBCC'

3 calls to _textimage_hex2rgb()
textimage_image_add_margin in ./textimage.module
This function adds a margin (or border) around an existing image resource
textimage_image_stroke_change_pixels in ./textimage.module
Utility function for image_stroke. Analyzes surrounding pixels and determines opacity of a pixel at that x-y coordinate
textimage_text_to_image in ./textimage.module
Generate an image containing text with the given parameters.

File

./textimage.module, line 1226

Code

function _textimage_hex2rgb($hex) {
  $hex = ltrim($hex, '#');
  if (preg_match('/^[0-9a-f]{3}$/i', $hex)) {

    // 'FA3' is the same as 'FFAA33' so r=FF, g=AA, b=33
    $r = str_repeat($hex[0], 2);
    $g = str_repeat($hex[1], 2);
    $b = str_repeat($hex[2], 2);
  }
  elseif (preg_match('/^[0-9a-f]{6}$/i', $hex)) {

    // #FFAA33 or r=FF, g=AA, b=33
    $r = substr($hex, 0, 2);
    $g = substr($hex, 2, 2);
    $b = substr($hex, 4, 2);
  }
  $r = hexdec($r);
  $g = hexdec($g);
  $b = hexdec($b);
  return array(
    $r,
    $g,
    $b,
  );
}