CMYK color space is invalid for ImagickDraw
Posted: 2016-06-23T16:28:05-07:00
The sample code is below. $fg and $lg used in ImagickDraw are unexcepted in image.
php 5.6.21
Imagick compiled with ImageMagick version => ImageMagick 6.7.8-9 2016-03-31 Q16 http://www.imagemagick.org
php 5.6.21
Imagick compiled with ImageMagick version => ImageMagick 6.7.8-9 2016-03-31 Q16 http://www.imagemagick.org
Code: Select all
$fg = "cmyk(0,0,0,100)";
$bg = "cmyk(0,1,0,0)";
$lg = "cmyk(1,0,0,0)";
$image_size = 200;
$fg_pixel = new ImagickPixel($fg);
$bg_pixel = new ImagickPixel($bg);
$lg_pixel = new ImagickPixel($lg);
$image = new Imagick();
$image->newImage($image_size, $image_size, $bg_pixel);
$image->setImageColorspace(Imagick::COLORSPACE_CMYK);
$image->setImageFormat('jpeg');
$profiles = $image->getImageProfiles('*', false);
$has_icc_profile = (array_search('icc', $profiles) !== false);
if ($has_icc_profile === false) {
echo "load icc file.\n";
$icc_cmyk = file_get_contents('JapanColor2001Coated.icc');
$image->profileImage('icc', $icc_cmyk);
unset($icc_cmyk);
}
$draw = new ImagickDraw();
$draw->setStrokeColor($lg_pixel);
$draw->setFillColor($fg_pixel);
$draw->setStrokeWidth(6);
$draw->rectangle(30,30,80,80);
$image->drawImage($draw);
$image->writeImage("cmyk.jpg");
$fg_pixel->destroy();
$bg_pixel->destroy();
$draw->destroy();
$image->destroy();