I create a cmyk image by php imagemagick, but cmyk color is different on photoshop?

时光总嘲笑我的痴心妄想 提交于 2019-12-01 14:33:23

You need to set the colorspace to CMYK, other wise your pixels will be converted to RGB.

$img->setImageColorspace(Imagick::COLORSPACE_CMYK);

http://php.net/manual/en/imagick.setimagecolorspace.php

Also all make sure that you are using file type that supports CMYK. ( eg. .jpg, .tif )

Edit

It seems Imagick has a bug. Until it is fixed you can try and use this work around using transformImageColorspace.

$draw = new \ImagickDraw();

$fillColor = new \ImagickPixel();    
$fillColor->setColor('cmyk(0%,0%,0%,100%');
$draw->setFillColor($fillColor);
$draw->rectangle(100, 100, 400, 400);

$img = new \Imagick();
$img->newImage(500, 500, 'white');
$img->drawImage($draw);
$img->transformImageColorspace(Imagick::COLORSPACE_CMYK);
$img->setImageFormat("jpg");

header('Content-Type: image/'.$img->getImageFormat());
echo $img;
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!