CMYK

The CMYK colour model in tc-lib-color: four subtractive components, key extraction, and the DeviceCMYK operator

Cyan, magenta, yellow and a black key, one component per process plate. This is the colour space a press sheet is specified in and the alternate space most spot colours fall back to. The conversion from RGB is exact arithmetic and round-trips at 8-bit precision.

Model

ItemValue
Type stringCMYK
Enum caseColorModelType::Cmyk
Class\Com\Tecnick\Color\Model\Cmyk
PDF colour spaceDeviceCMYK
Notationscmyk(), cmyka(), ["CMYK",c,m,y,k]

cmyk() and cmyka() are notations of this library, not CSS functions.

Components

ComponentKeyRangeOut of range
Cyancyan0.0 to 1.0clamped
Magentamagenta0.0 to 1.0clamped
Yellowyellow0.0 to 1.0clamped
Key (black)key0.0 to 1.0clamped
Alphaalpha0.0 to 1.0, default 1.0clamped

Construction

<?php

require_once __DIR__ . '/vendor/autoload.php';

$cmyk = new \Com\Tecnick\Color\Model\Cmyk([
    'cyan' => 2 / 3,
    'magenta' => 1 / 3,
    'yellow' => 0.0,
    'key' => 0.4,
]);

echo $cmyk->getCssColor(), "\n";
echo $cmyk->getPdfColor();
echo $cmyk->getRgbHexColor(), "\n";
cmyk(66.6667%,33.3333%,0%,40%)
0.666667 0.333333 0.000000 0.400000 k
#336699

Output

Every accessor, against #336699:

CallResult
getCssColor()cmyk(66.6667%,33.3333%,0%,40%)
getRgbHexColor()#336699
getRgbaHexColor()#336699ff
getComponentsString()0.666667 0.333333 0.000000 0.400000
getPdfColor()0.666667 0.333333 0.000000 0.400000 k
getPdfColor(true)0.666667 0.333333 0.000000 0.400000 K
getJsPdfColor()["CMYK",0.666667,0.333333,0.000000,0.400000]
getArray()['C' => 0.6666666666666667, 'M' => 0.33333333333333326, 'Y' => 0.0, 'K' => 0.4, 'A' => 1.0]
getNormalizedArray(255)['C' => 170.0, 'M' => 85.0, 'Y' => 0.0, 'K' => 102.0, 'A' => 1.0]
getPDFacArray()[0.6666666666666667, 0.33333333333333326, 0.0, 0.4]

getNormalizedArray(255) scales all four components to 255. Ink coverage is normally expressed in percent, which getCssColor() emits.

Key Extraction

The conversion complements the three RGB channels and pulls the common minimum out into the key component. Full black is the special case: it comes out as cmyk(0%,0%,0%,100%) rather than as four full components.

$web = new \Com\Tecnick\Color\Web();

foreach (['#000000', '#333333', '#ff0000', '#336699'] as $hex) {
    $cmyk = \Com\Tecnick\Color\Model::create('CMYK', $web->getColorObj($hex)->toCmykArray());
    printf("%-9s %s\n", $hex, $cmyk->getCssColor());
}
#000000   cmyk(0%,0%,0%,100%)
#333333   cmyk(0%,0%,0%,80%)
#ff0000   cmyk(0%,100%,100%,0%)
#336699   cmyk(66.6667%,33.3333%,0%,40%)

What The Conversion Does

toCmykArray() complements the three RGB channels, extracts their common minimum as the key and rescales the remainder. No profile, lookup table or configuration is involved, and the result returns to its original bytes: all 150 named colours round-trip through CMYK at 8-bit precision, as Conversions measures.

This is the conversion behind the k operator on PDF Output and behind the CMYK equivalent stored for a spot colour. Black generation, undercolour removal and a total ink limit come from an ICC profile: take those values from the profile in use and hold them as CMYK from the start.

A DeviceCMYK colour in a PDF/A document is only valid when the output intent is a CMYK profile. tc-lib-pdf reports the mismatch through getWarnings(); see /docs/standards/.

See Also