Fixed: Several fix in color management (function at wrong place, mark

param that are deprecated, convertion of value to get correct
format in all situation)
This commit is contained in:
Laurent Destailleur
2014-12-08 19:05:22 +01:00
parent f1ec0348ce
commit a8052d8ea4
5 changed files with 52 additions and 24 deletions

View File

@@ -1836,3 +1836,42 @@ function fetchObjectByElement($element_id,$element_type) {
}
return 0;
}
/**
* Convert an array with RGB value into hex RGB value
*
* @param array $arraycolor Array
* @param string $colorifnotfound Color code to return if entry not defined
* @return string RGB hex value (without # before). For example: FF00FF
* @see Make the opposite of colorStringToArray
*/
function colorArrayToHex($arraycolor,$colorifnotfound='888888')
{
if (! is_array($arraycolor)) return $colorifnotfound;
return dechex($arraycolor[0]).dechex($arraycolor[1]).dechex($arraycolor[2]);
}
/**
* Convert a string RGB value ('FFFFFF', '255,255,255') into an array RGB array(255,255,255)
*
* @param string $stringcolor String with hex (FFFFFF) or comma RGB ('255,255,255')
* @param string $colorifnotfound Color code to return if entry not defined
* @return string RGB hex value (without # before). For example: FF00FF
* @see Make the opposite of colorArrayToHex
*/
function colorStringToArray($stringcolor,$colorifnotfound=array(88,88,88))
{
if (is_array($stringcolor)) return $stringcolor; // If already into correct output format, we return as is
$tmp=preg_match('/^([0-9a-fA-F][0-9a-fA-F])([0-9a-fA-F][0-9a-fA-F])([0-9a-fA-F][0-9a-fA-F])$/',$stringcolor,$reg);
if (! $tmp)
{
$tmp=explode(',',$stringcolor);
if (count($tmp) < 3) return $colorifnotfound;
return $tmp;
}
return array(hexdec($reg[1]),hexdec($reg[2]),hexdec($reg[3]));
}