Page 1 of 1

CMYK color space is invalid for ImagickDraw

Posted: 2016-06-23T16:28:05-07:00
by Donghua.Lau
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

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();

Re: CMYK color space is invalid for ImagickDraw

Posted: 2016-06-23T16:39:33-07:00
by snibgo
Imagick wasn't written by, and isn't supported by, the ImageMagick team. If you think Imagick has a bug, I suggest you report it to them.

Re: CMYK color space is invalid for ImagickDraw

Posted: 2016-06-23T19:36:39-07:00
by fmw42
I do not believe the Imagemagick -draw works with CMYK images. I think it needs to draw on an RGB image, since it converts CMYK color values into RGB before drawing. However, I will defer to one of the IM developers to correct me if I am wrong.