|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #62285 ImagickDraw cannot use CMYK colors
Submitted: 2012-06-10 16:16 UTC Modified: 2015-01-18 04:22 UTC
Avg. Score:4.5 ± 0.5
Reproduced:6 of 6 (100.0%)
Same Version:4 (66.7%)
Same OS:5 (83.3%)
From: mk at alpha-q dot de Assigned: mkoppanen (profile)
Status: No Feedback Package: imagick (PECL)
PHP Version: Irrelevant OS: Linux
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If this is not your bug, you can add a comment by following this link.
If this is your bug, but you forgot your password, you can retrieve your password here.
Bug Type:
From: mk at alpha-q dot de
New email:
PHP Version: OS:


 [2012-06-10 16:16 UTC] mk at alpha-q dot de
If you set a CMYK color with setFillColor to an ImagickDraw object, it will not be 
handled correctly. The color is misinterpreted and returned as an RGB color (look 
at example).

This makes it nearly impossible to create valid CMYK images. There is a little, 
but not always working, workaround: You can provide the CMYK color as a HEX value, 
eg cmyk(0, 85, 100, 0) => 00d9ff, but the fourth CMYK value ("K") has to be 0.

Test script:
$drawText = new ImagickDraw();

$color = new ImagickPixel("cmyk(75, 68, 67, 90)");
// Outputs cmyk(75,68,67,90)
echo $color->getColorAsString();

$color2 = $drawText->getFillColor();
// Outputs rgb(0,0,0)
echo $color2->getColorAsString();

Expected result:
Both times the output should be "cmyk(75,68,67,90)" and the color should also used 
correctly to draw text, etc.


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2013-12-03 11:30 UTC]
-Assigned To: +Assigned To: mkoppanen
 [2014-08-01 08:06 UTC] adri74 at hotmail dot fr
For those who are interested in creating pure CMYK images with Imagick, you can use the importImagePixels function as a workaround. A little demo :

$oImage = new Imagick();

$iWidth = 100;
$iHeight = 100;

$aCMYK = array();
for ($iX = 0; $iX < $iWidth; $iX++){
	for ($iY = 0; $iY < $iHeight; $iY++){
		$aCMYK[] = $iX / $iWidth * 255;
		$aCMYK[] = $iY / $iHeight * 255;
		$aCMYK[] = 0;
		$aCMYK[] = 0;
$oImage->newImage($iWidth, $iHeight, 'transparent');
$oImage->importImagePixels(0, 0, $iWidth, $iHeight, "CMYK", Imagick::PIXEL_CHAR, $aCMYK);

header("Content-Type: image/jpg");
echo $oImage;
 [2015-01-05 03:26 UTC]
-Status: Assigned +Status: Feedback
 [2015-01-05 03:26 UTC]

If you want a CMYK image you need to set the colorspace of the image to CMYK e.g.:

$im = new Imagick();
$im->newImage(500, 500, new ImagickPixel('rgba(255,255,255)'), 'png');

If that doesn't do what you want, please can you provide a complete example that produces an image, and describe how it doesn't meet your expectations?
 [2015-01-05 09:48 UTC] adri74 at hotmail dot fr
$oImage = new Imagick();
$oImage->newImage(50, 50, 'transparent', 'jpg');
for ($i = 0; $i < 50; $i++){
	for ($j = 0; $j < 25; $j++){
		$oImage->importImagePixels($i, $j, 1, 1, "CMYK", Imagick::PIXEL_CHAR, array(255, 0, 0, 127));
	for ($j = 25; $j < 50; $j++){
		$oDraw = new ImagickDraw();
		$oColor = new ImagickPixel("cmyk(100,0,0,50)");
		$oDraw->point($i, $j);

header("Content-Type: image/jpg");
echo $oImage;

Normally, the image should be completely painted in "dark cyan", with top and bottom parts in the same color.

Instead, the top part (importImagePixels) is correctly painted in dark cyan, but the bottom part (setFillColor) is painted in dark red.
 [2015-01-18 04:22 UTC] pecl-dev at lists dot php dot net
No feedback was provided. The bug is being suspended because
we assume that you are no longer experiencing the problem.
If this is not the case and you are able to provide the
information that was requested earlier, please do so and
change the status of the bug back to "Re-Opened". Thank you.
PHP Copyright © 2001-2021 The PHP Group
All rights reserved.
Last updated: Sun Sep 19 15:03:37 2021 UTC