Repository: Intervention/image

Issue #707: Color Profile Issue, can't seem to find the solution. Washed out images with imagick (or gd).
Created: 2017-03-30T20:05:23Z
Hi,
I saw that this issue has been discussed several times before and has been either dismissed or was specific for one kind of conversion.
Here is the scenario:
I have users uploading images of artwork in their accounts to display. I use image intervention through thephpleague/glide in order to display the images in different sizes. The original images can be in different formats and may have different profiles, I cannot ask my users to prepare the images fro web in sRGB.
I am using the imagick driver (have tried gd before, which was worse).
I have a simple example with a jpg image with adobe RGB 1998 as profile. This image comes out slightly washed out, most colors are a little dull.
If I save the image in photoshop with sRGB before upload all is fine. Just when I upload an image with the adobe profile it looks washed out. Other, more exotic profiles might look completely off.
Anyhow, as far as I understand: The image is stripped from its profile and not converted to the default sRGB profile before this happens. I dont necessarily undertsand how this is a good practice. Is there any way I could implement conversion? Obviously if the colors would be properly mapped between the profiles before the profiles are stripped the image coloration wouldn't be so off. Or am I missing something?
For now for my own purpose I have included the following procedure before giving an image to image intervention, which fixes the issue:
        //make sure image is properly converted to srgb
        //inspired by https://github.com/mosbth/cimage/blob/master/CImage.php#L2552
        $image      = new \Imagick($tmp);
        $colorspace = $image->getImageColorspace();
        $profiles      = $image->getImageProfiles('*', false);
        $hasICCProfile = (array_search('icc', $profiles) !== false);
        if ($colorspace != \Imagick::COLORSPACE_SRGB || $hasICCProfile) {
            $sRGBicc = file_get_contents(base_path('resources/icc/sRGB_IEC61966-2-1_black_scaled.icc'));
            $image->profileImage('icc', $sRGBicc);
            $image->transformImageColorspace(\Imagick::COLORSPACE_SRGB);
            $image->writeImage($tmp);
        }

All best,
T

Duplicate issue #616: make() changes colorspace of the image
Created: 2016-09-22T09:38:05Z
Hi there!
I update the issue as after doing some more tests I noticed the error is somewhere else. I'm pretty certain that the image I'm opening is CMYK, but it gets opened as SRGB, so whenever I try to resize it generates a new image but with a wrong color space, so the original and the thumbnail looks pretty different.
Cheers!
Jesús E.

Closing comment (2021-05-11T22:45:00Z): I still got this issue also. For those using GD I don't know if a solution exists, but with Imagick we could use Imagick::transformImageColorspace.
For now I convert the image to sRGB (as this stackoverflow answer suggests) before doing any manipulation with Intervention. It's not efficient but it works. In my case it's not a big deal since I already cache my image in order to bypass the image processing, which yields good results in terms of performances.
$imagick = new \Imagick($inputPath);
$imagick->transformImageColorspace(\Imagick::COLORSPACE_SRGB);
$imagick->writeImage($outputPath);

Image::make($outputPath)->resize($maxsize, $maxsize, function ($constraint) {
  $constraint->aspectRatio();
  $constraint->upsize();
})->save($outputPath)
Hoping it will help some of us.
related to #707
EDIT : Actually I realize that the simple fact to use Imagick instead of gd fixed my issue, I didn't need to transform the colorspace beforehand. But it might depends on the version of Imagick you're using. On my side I use ImageMagick 6.9.10-23 Q16 x86_64 20190101 with the module version 3.4.4.