corrade-http-templates – Rev 77

Subversion Repositories:
Rev:
<?php

///////////////////////////////////////////////////////////////////////////
//  Copyright (C) Wizardry and Steamworks 2015 - License: GNU GPLv3      //
///////////////////////////////////////////////////////////////////////////
function wasColorHash($a) {
  $hash = sha1($a);
  $size = strlen($hash);

  return substr($hash, 0, 2).
         substr($hash, $size/2, 2).
         substr($hash, $size-2, 2);
}

function hex2RGB($hexStr, $returnAsString = false, $seperator = ',') {
    $hexStr = preg_replace("/[^0-9A-Fa-f]/", '', $hexStr);
    $rgbArray = array();
    switch(strlen($hexStr)) {
        case 6:
            $colorVal = hexdec($hexStr);
            $rgbArray['red'] = 0xFF & ($colorVal >> 0x10);
            $rgbArray['green'] = 0xFF & ($colorVal >> 0x8);
            $rgbArray['blue'] = 0xFF & $colorVal;
            break;
        case 3:
            $rgbArray['red'] = hexdec(
                str_repeat(substr($hexStr, 0, 1), 2));
            $rgbArray['green'] = hexdec(
                str_repeat(substr($hexStr, 1, 1), 2));
            $rgbArray['blue'] = hexdec(
                str_repeat(substr($hexStr, 2, 1), 2));
            break;
        default:
            return false;
    }
    return $returnAsString ? implode($seperator, $rgbArray) : $rgbArray;
}