A couple of years ago I was working on online business card design and print web application. There was a need to show customer color options for text, border and background. As we had color in CMYK space we had to convert it to WEB color used on screen - to RGB color space. Looked like a simple task to create a PHP function using some mathematical equation. But not really. Web representation of CMYK color was not acurate at all.

New idea was to use a CMYK image converted by Adobe Photoshop to RGB as a conversion map. This way we can even have different image map for different display color workspace/profile.

Demo

Conversion map is an image of size 441 x 441 pixels where each pixel represents different color covering all CMYK space in 5% steps:
cmyk_map_sRGB-IEC61966-21.png

PHP script simply finds pixel on position given by CMYK values and returns its RGB value:

function cmyk2rgb($c, $m, $y, $k, $cmykMap='') {

    $x = round($y/5) * 21 + round($c/5);
    $y = round($k/5) * 21 + round($m/5);

    if(!$cmykMap) $cmykMap = dirname(__FILE__).'/cmyk_map_sRGB-IEC61966-21.png';
    if(!file_exists($cmykMap)) return false;

    $im = ImageCreateFromPng($cmykMap);
    $rgb = ImageColorAt($im, $x, $y);
    $r = ($rgb >> 16) & 0xFF;
    $g = ($rgb >> 8) & 0xFF;
    $b = $rgb & 0xFF;

    return array(
        'r' => $r,
        'g' => $g,
        'b' => $b,
        'rgb' => "{$r}, {$g}, {$b}",
        'hex' => sprintf("#%02X%02X%02X", $r, $g, $b)
    );
}

Returned is an array containing individual RGB values, comma separated RGB values string and WEB color in hex format with hash e.g. #ff00CC. As default conversion image is used cmyk_colorspace.png located in same directory as the script.

To create own conversion image map open cmyk_map.tif (CMYK image) in Photoshop and save it for web as PNG. Photoshop will use current color profile.

Download files: cmyk2rgb.zip

  1. If you want to choose images, and selected size for your art. We are one of the best and affordable in Australia with quality service. With best print result, quality images with the size that you want to enlarge. Canvas Prints Online in Australia is your choice.

Leave a Comment »