CMYK color space is invalid for ImagickDraw

IMagick is a native PHP extension to create and modify images using the ImageMagick API. ImageMagick Studio LLC did not write nor does it maintain the IMagick extension, however, IMagick users are welcome to discuss the extension here.
Post Reply
Donghua.Lau
Posts: 1
Joined: 2016-06-23T16:19:52-07:00
Authentication code: 1151

CMYK color space is invalid for ImagickDraw

Post 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();
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: CMYK color space is invalid for ImagickDraw

Post 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.
snibgo's IM pages: im.snibgo.com
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: CMYK color space is invalid for ImagickDraw

Post 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.
Post Reply