You are here

function hex_to_rgb in ImageCache Actions 6.2

Same name and namespace in other branches
  1. 5.3 utility.inc \hex_to_rgb()
  2. 5.2 utility.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

4 calls to hex_to_rgb()
imagecache_alpha_image in coloractions/transparency.inc
Given an image, manipulate the transparancy behaviour.
imagecache_coloroverlay_image in coloractions/imagecache_coloractions.module
Implementation of hook_image()
imagecache_colorshift_image in coloractions/imagecache_coloractions.module
Implementation of hook_image()
imagecache_rgb_form in ./utility-color.inc
Prepare a subform for displaying RGB fields

File

./utility-color.inc, line 92
Utility functions for color widgets

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;
}