note 42218 added to function.hexdec
| From: | _metoALT+qweb dot de at rn2 dot php dot net | Date: | Sat, 08 May 2004 13:00:05 +0000 |
| Subject: | note 42218 added to function.hexdec | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-69340@lists.php.net to get a copy of this message | ||
Damn, this took me some real long time! Maybe it's helpfull for those who even have no idea of
color-Schemes like me ;)
If u want to generate PDF's for Print Offices u need to set all the colors in CMYK.
Here is a Function that will convert RGB to CMYK
<?
function hex2rgb($hex) {
$color = str_replace('#','',$hex);
$rgb = array('r' => hexdec(substr($color,0,2)),
'g' => hexdec(substr($color,2,2)),
'b' => hexdec(substr($color,4,2)));
return $rgb;
}
function rgb2cmyk($var1,$g=0,$b=0) {
if(is_array($var1)) {
$r = $var1['r'];
$g = $var1['g'];
$b = $var1['b'];
}
else $r=$var1;
$cyan = 255 - $r;
$magenta = 255 - $g;
$yellow = 255 - $b;
$black = min($cyan, $magenta, $yellow);
$cyan = @(($cyan - $black) / (255 - $black)) * 255;
$magenta = @(($magenta - $black) / (255 - $black)) * 255;
$yellow = @(($yellow - $black) / (255 - $black)) * 255;
return array('c' => $cyan / 255,
'm' => $magenta / 255,
'y' => $yellow / 255,
'k' => $black / 255);
}
$color=rgb2cmyk(hex2rgb('#FF0000'));
pdf_setcolor($pdf, "both", "cmyk", $color['c'], $color['m'],
$color['y'], $color['k']);
?>
U can call it with parameters (r,g,b) or just with an array(r,g,b) that contains these values.
Hope it works correct. All testing was fine.
----
Manual Page -- http://www.php.net/manual/en/function.hexdec.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+42218
Delete -- http://master.php.net/manage/user-notes.php?action=delete+42218&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+42218&report=yes
Search -- http://master.php.net/manage/user-notes.php