yurkinx / yii2-image

Yii2 Framework extension for image manipulating using Kohana Image Library

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Colorspace handling in Imagick

ebuzzz opened this issue · comments

I'm trying to scale a JPEG image with CMYK colorspace. This resulted in an inverted image. I traced the problem back to the Kohana_Image_Imagick class. I know this is an 'external' library, but do we need to be compatible with the upstream version? Or is the current version hardcoded because it's already modified for this project?

About the bug itself: the class does this in a few occasions:

$image->setColorspace($this->im->getColorspace());

AFAIK, this does nothing. According to the PHP manual, these methods get and set the global colorspace of the library. This always returns 0 in my setup. The methods setImageColorspace and getImageColorspace return info local to the image object.

Also, the _do_adapt method doesn't handle colorspaces at all. This is the main problem in my setup, because it results in inverted images.

I see two possibilities:

  • Change and add the setColorspace/getColorspace calls to the setImage/getImage variants. This will result in images with the same colorspace as the original.
  • Always transform the colorspace to RGB at the start of the class and use it as default colorspace. This will result in RGB images.

I believe the GD library always returns RGB, but I can't find 100% proof of this. If this is the case, it would be better to use option 2, so both backends do the same thing.

I've added pull #15 with my current solution that I use in production