note 101873 added to function.pdf-setcolor

From: Date: Sat, 15 Jan 2011 00:39:36 +0000
Subject: note 101873 added to function.pdf-setcolor
Groups: php.notes 
Request: Send a blank email to php-notes+get-175775@lists.php.net to get a copy of this message
Here is a quick snippet to convert CMYK to RGB. It has better precision than a lot of other solutions that also don't factor in colour profiles. <?php $cmyk = '10,20,100,31'; list($c, $m, $y, $k) = explode(',', $cmyk); # Gets the rgb as floats (cast via (int) if you want int ) $r = (1 - min(($c / 100) * (1 - $k /= 100) + 1 * $k, 1)) * 255; $g = (1 - min(($m / 100) * (1 - $k) + 1 * $k, 1)) * 255; $b = (1 - min(($y / 100) * (1 - $k) + 1 * $k, 1)) * 255; echo "$r $g $b\r\n"; # Converts the rgb to hex with leading 0's $r = str_pad(dechex($r), 2, '0', STR_PAD_LEFT); $g = str_pad(dechex($g), 2, '0', STR_PAD_LEFT); $b = str_pad(dechex($b), 2, '0', STR_PAD_LEFT); echo "hex: $r$g$b\r\n"; /* an example to see the colour via html echo '<div style="width: 80px; height: 80px; background-color: #', "$r$g$b", '"></div>'; */ ?> ---- Server IP: 69.147.83.197 Probable Submitter: 94.190.193.169 ---- Manual Page -- http://www.php.net/manual/en/function.pdf-setcolor.php Edit -- https://master.php.net/note/edit/101873 Del: integrated -- https://master.php.net/note/delete/101873/integrated Del: useless -- https://master.php.net/note/delete/101873/useless Del: bad code -- https://master.php.net/note/delete/101873/bad+code Del: spam -- https://master.php.net/note/delete/101873/spam Del: non-english -- https://master.php.net/note/delete/101873/non-english Del: in docs -- https://master.php.net/note/delete/101873/in+docs Del: other reasons-- https://master.php.net/note/delete/101873 Reject -- https://master.php.net/note/reject/101873 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#175775) next »