Colour tests
// pass 1: original
function cmyk_to_rgb1($c, $m, $y, $k)
{
$r = 255 - round(2.55 * ($c+$k)) ;
$g = 255 - round(2.55 * ($m+$k)) ;
$b = 255 - round(2.55 * ($y+$k)) ;
if($r<0) $r = 0 ;
if($g<0) $g = 0 ;
if($b<0) $b = 0 ;
$o->r = $r ;
$o->g = $g ;
$o->b = $b ;
return $o ;
}
// pass 2: voisen's
function cmyk_to_rgb2($c, $m, $y, $k)
{
// Convert percentages to 0 – 255 range
$c = (0xFF * $c) / 100;
$m = (0xFF * $m) / 100;
$y = (0xFF * $y) / 100;
$k = (0xFF * $k) / 100;
$r = ( round( ((255 - $c) * (255 - $k)) / 255 ) );
$g = ( round( (255 - $m) * (255 - $k) / 255 ) );
$b = ( round( (255 - $y) * (255 - $k) / 255 ) );
$o->r = $r ;
$o->g = $g ;
$o->b = $b ;
return $o ;
}
// convert rgb to hex for display
function to_hex($o)
{
$r = $o->r ;
$g = $o->g ;
$b = $o->b ;
if(!$r > 255 || $g > 255 || $b > 255){
return false ;
}
$r = dechex($r) ;
$g = dechex($g) ;
$b = dechex($b) ;
if(strlen($r) == 1) $r = '0' . $r ;
if(strlen($g) == 1) $g = '0' . $g ;
if(strlen($b) == 1) $b = '0' . $b ;
return '#' . $r . $g . $b ;
}
// the set of cmyk colours we want to work with
$colours = array(
// no k
'100,0,0,0' ,
'100,50,0,0' ,
'50,50,0,0' ,
'50,100,0,0' ,
'0,100,0,0' ,
'0,100,50,0' ,
'0,50,50,0' ,
'0,50,100,0' ,
'0,0,100,0' ,
'50,0,100,0' ,
'50,0,50,0' ,
'100,0,50,0' ,
// k = 33
'100,0,0,33' ,
'100,50,0,33' ,
'50,50,0,33' ,
'50,100,0,33' ,
'0,100,0,33' ,
'0,100,50,33' ,
'0,50,50,33' ,
'0,50,100,33' ,
'0,0,100,33' ,
'50,0,100,33' ,
'50,0,50,33' ,
'100,0,50,33' ,
// k = 66
'100,0,0,66' ,
'100,50,0,66' ,
'50,50,0,66' ,
'50,100,0,66' ,
'0,100,0,66' ,
'0,100,50,66' ,
'0,50,50,66' ,
'0,50,100,66' ,
'0,0,100,66' ,
'50,0,100,66' ,
'50,0,50,66' ,
'100,0,50,66' ,
) ;
// populate the cmyk source array with these colours, each at 5 levels of transparency
$cmyk = array() ;
foreach($colours as $c){
$c = explode(',', $c) ;
$cmyk[] = array($c[0] * 0.2, $c[1] * 0.2, $c[2] * 0.2, $c[3] * 0.2) ;
$cmyk[] = array($c[0] * 0.4, $c[1] * 0.4, $c[2] * 0.4, $c[3] * 0.4) ;
$cmyk[] = array($c[0] * 0.6, $c[1] * 0.6, $c[2] * 0.6, $c[3] * 0.6) ;
$cmyk[] = array($c[0] * 0.8, $c[1] * 0.8, $c[2] * 0.8, $c[3] * 0.8) ;
$cmyk[] = array($c[0] * 1.0, $c[1] * 1.0, $c[2] * 1.0, $c[3] * 1.0) ;
}
// these are the matching rgb colours as converted by illustrator (scraped from the svg export)
$rgb = explode("\n", '#CCECF4
#99D9E8
#66C6DD
#33B3D1
#00A0C6
#CEDCEC
#9DB9D9
#6C96C7
#3B73B4
#0A50A1
#E6E1EF
#CCC3DF
#B3A5D0
#9987C0
#8069B0
#E6CCE5
#CD99CB
#B367B2
#9A3498
#81017E
#FCCCE5
#F99ACC
#F667B2
#F33599
#F0027F
#FECCD9
#FC99B2
#FB668C
#F93365
#F8003F
#FEE6DF
#FDCCBF
#FDB39F
#FC997F
#FB805F
#FFE5CC
#FFCC99
#FFB266
#FF9933
#FF7F00
#FFFFCC
#FFFF99
#FFFF66
#FFFF33
#FFFF00
#E5F3D2
#CCE7A4
#B2DB77
#99CF49
#7FC31C
#E5F3E5
#CCE7CB
#B2DCB1
#99D097
#7FC47D
#CCE9E5
#99D3CB
#66BCB0
#33A696
#00907C
#CFD2D8
#9EA6B2
#6E798B
#3D4D65
#0D203E
#CFD2D8
#9EA6B2
#6E798B
#3D4D65
#0D203E
#D9D6DD
#B3AEBB
#8C859A
#665D78
#403456
#D9CDD8
#B39BB2
#8C698B
#663765
#40053E
#E4CDD8
#C99AB2
#AD688B
#923565
#77033E
#E4CDD2
#CA9CA6
#AF6A79
#95394D
#7A0720
#E4D9D5
#CAB3AC
#AF8C82
#956659
#7A402F
#E5D9CE
#CBB29C
#B08C6B
#966539
#7C3F08
#E5D9CE
#CBB29C
#B08C6B
#966539
#7C3F08
#D9DFCF
#B2BF9F
#8C9F70
#657F40
#3F5F10
#D9DFD8
#B2C0B2
#8CA08B
#658165
#3F613E
#D9DFD8
#B2C0B2
#8CA08B
#658165
#3F613E
#CED0D3
#9DA0A7
#6C717A
#3B414E
#0A1222
#CED0D3
#9DA0A7
#6C717A
#3B414E
#0A1222
#D2D1D4
#A4A2A8
#77747D
#494551
#1C1726
#D2CDD2
#A59BA5
#786A78
#4B384B
#1E061E
#D7CDD2
#AF9BA5
#886A77
#60384A
#38061D
#D7CDCF
#B09B9F
#88696F
#61373F
#39050F
#D7D2D0
#B0A5A2
#887873
#614B45
#391E16
#D7D2CD
#B0A59B
#887768
#614A36
#391D04
#D7D2CD
#B0A59B
#887768
#614A36
#391D04
#D1D4CE
#A3A99D
#767E6D
#48533C
#1A280B
#D1D4D1
#A3A9A3
#767F76
#485448
#1A291A
#D1D4D1
#A3A9A3
#767F76
#485448
#1A291A') ;
// do the conversions for each pass
$functions = array('cmyk_to_rgb1', 'cmyk_to_rgb2') ;
$names['cmyk_to_rgb1'] = 'Pass 1 ' ;
$names['cmyk_to_rgb2'] = 'Pass 2 ' ;
$results = array() ;
foreach($cmyk as $c){
foreach($functions as $f){
$results[$f][] = to_hex($f($c[0], $c[1], $c[2], $c[3])) ;
}
}
// output a table of results
?>
0% K |
CMYK |
foreach($cmyk as $i => $c){ ?>
if($i>=60) break ; ?>
|
} ?>
foreach($functions as $f){ ?>
= $names[$f] ?> |
foreach($cmyk as $i => $c){ ?>
if($i>=60) break ; ?>
|
} ?>
} ?>
|
33% K |
CMYK |
foreach($cmyk as $i => $c){ ?>
if($i<60) continue; ?>
if($i>=120) continue; ?>
|
} ?>
foreach($functions as $f){ ?>
= $names[$f] ?> |
foreach($cmyk as $i => $c){ ?>
if($i<60) continue ; ?>
if($i>=120) continue; ?>
|
} ?>
} ?>
|
66% K |
CMYK |
foreach($cmyk as $i => $c){ ?>
if($i<120) continue; ?>
|
} ?>
foreach($functions as $f){ ?>
= $names[$f] ?> |
foreach($cmyk as $i => $c){ ?>
if($i<120) continue ; ?>
|
} ?>
} ?>