CMYK

Subtractive ink percentages for print work.

Channels
  • C Cyan 0% to 100%
  • M Magenta 0% to 100%
  • Y Yellow 0% to 100%
  • K Black 0% to 100%
CSS syntax
device-cmyk()
White point
n/a
Category
Print
PHP class
CmykColor
Reach for it when
Print previews and naive ink conversion.

Convert to CMYK in PHP

Any color converts with to(); the result is CMYK, an object with its own channels.

<?php

$color = Color::parse('#3b82f6')->to('cmyk');

$color->getChannels();
// ['c' => 0.7602, 'm' => 0.4715, 'y' => 0, 'k' => 0.0353]
$color = Color::parse('#3b82f6')->to('cmyk'); $color->getChannels(); // ['c' => 0.7602, 'm' => 0.4715, 'y' => 0, 'k' => 0.0353]

Parse CMYK in PHP

The regular CSS syntax goes straight into Color::parse().

<?php

$color = Color::parse('device-cmyk(76% 47% 0% 4%)');

$color->toHex(); // #3b82f5
$color = Color::parse('device-cmyk(76% 47% 0% 4%)'); $color->toHex(); // #3b82f5

Export CMYK in CSS

Every color object serializes back to the CSS form of its space.

<?php

Color::parse('#3b82f6')->to('cmyk')->toCss();
// device-cmyk(76.0163% 47.1545% 0% 3.52941%)
Color::parse('#3b82f6')->to('cmyk')->toCss(); // device-cmyk(76.0163% 47.1545% 0% 3.52941%)

Validate CMYK

tryFrom() returns null on invalid input instead of throwing.

<?php

Color::tryFrom('device-cmyk(76% 47% 0% 4%)'); // instance

Color::tryFrom('device-cmyk(nope)'); // null
Color::tryFrom('device-cmyk(76% 47% 0% 4%)'); // instance Color::tryFrom('device-cmyk(nope)'); // null