You are here

function hex_to_rgb in ImageCache Actions 5.2

Same name and namespace in other branches
  1. 5.3 utility.inc \hex_to_rgb()
  2. 6.2 utility-color.inc \hex_to_rgb()
  3. 6 utility.inc \hex_to_rgb()

Decode an HTML hex-code into an array of R, G, and B values. accepts these formats: (case insensitive) #ffffff, ffffff, #fff, fff

7 calls to hex_to_rgb()
canvasactions_definecanvas_image in ./canvasactions.inc
Implementation of hook_image()
imagecache_alpha_image in ./transparency.inc
Given an image, manipulate the transparancy behaviour.
imagecache_colorshift_image in ./imagecache_coloractions.module
Implementation of hook_image()
imagecache_rgb_form in ./utility.inc
Prepare a subform for displaying RGB fields
png_color2alpha in ./transparency.inc
This achives a tonal effect by converting the images combined tone and existing transparency into one shade value. This is then used as the ALPHA transparency for that pixel, while the whole thing is coloured the same shade. Images…

... See full list

File

./utility.inc, line 88

Code

function hex_to_rgb($hex) {
  $hex = trim($hex);

  // remove '#'
  if (substr($hex, 0, 1) == '#') {
    $hex = substr($hex, 1);
  }

  // expand short form ('fff') color
  if (strlen($hex) == 3) {
    $hex = substr($hex, 0, 1) . substr($hex, 0, 1) . substr($hex, 1, 1) . substr($hex, 1, 1) . substr($hex, 2, 1) . substr($hex, 2, 1);
  }
  if (strlen($hex) != 6) {
    trigger_error('Error: Invalid color "' . $hex . '"');
  }

  // convert
  $rgb['red'] = hexdec(substr($hex, 0, 2));
  $rgb['green'] = hexdec(substr($hex, 2, 2));
  $rgb['blue'] = hexdec(substr($hex, 4, 2));
  return $rgb;
}