Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP imagick converting image from CMYK to RGB inverts image

Tags:

php

rgb

imagick

I have an image being rejected by the eBay API because of this:

 <ShortMessage>Source picture uses an unsupported colorspace.</ShortMessage>
    <LongMessage>Pictures with a CMYK colorspace are not supported; source pictures must use a RGB colorspace compatible with all web browsers supported by eBay. Submit pictures created using a camera or scanner set to save images with RGB color.</LongMessage>

Well, I had no idea it was a CMYK nor am I even sure how to tell. I then used the following code to attempt a convert:

$image= "$img.jpg";
$i = new Imagick($image);
$i->setImageColorspace(Imagick::COLORSPACE_SRGB);
$i->writeImage($image);
$i->destroy();

It converts (and is now accepted by eBay), but it also inverts the colors of the picture. Why would it do this and is there another COLORSPACE I should be using?

Thanks.

like image 649
user2029890 Avatar asked Jan 09 '23 11:01

user2029890


1 Answers

The setImageColorSpace method is not meant to be used for existing images - it's only for new images (e.g. $imagick->newPseudoImage(100, 100, "xc:gray");)

The transformImageColorSpace method is the right one to use for changing an existing images colorspace.

$image= "$img.jpg";
$i = new Imagick($image);
$i->transformImageColorspace(Imagick::COLORSPACE_SRGB);
$i->writeImage($image);
$i->destroy();
like image 87
Danack Avatar answered Jan 20 '23 13:01

Danack