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

前端 未结 1 1083
故里飘歌
故里飘歌 2021-01-17 06:47

NEED HELP! I create a cmyk image by php imagemagick, but cmyk color is different on photoshop! e.g.: set ImagickPixel color cmyk(0,0,0,100)(black), but found cmyk(61,61,61,0

相关标签:
1条回答
  • 2021-01-17 07:03

    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;
    
    0 讨论(0)
提交回复
热议问题