php.net |  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
Votes:6
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
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please — but make sure to vote on the bug!
Your email address:
MUST BE VALID
Solve the problem:
29 - 14 = ?
Subscribe to this entry?

 
 [2012-06-10 16:16 UTC] mk at alpha-q dot de
Description:
------------
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();

$drawText->setFillColor($color);
$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.


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2013-12-03 11:30 UTC] mike@php.net
-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);

$oImage->setImageFormat('jpg');
header("Content-Type: image/jpg");
echo $oImage;
 [2015-01-05 03:26 UTC] danack@php.net
-Status: Assigned +Status: Feedback
 [2015-01-05 03:26 UTC] danack@php.net
Hi,

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');
$im->setImageColorspace(Imagick::COLORSPACE_CMYK);




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');
$oImage->setImageColorspace(Imagick::COLORSPACE_CMYK);
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->setFillColor($oColor);
		$oDraw->point($i, $j);
		$oImage->drawImage($oDraw);
	}
}

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-2024 The PHP Group
All rights reserved.
Last updated: Tue Apr 16 12:01:29 2024 UTC