|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[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.
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Mon Oct 27 10:00:01 2025 UTC |
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;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?$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.