DaanAmsterdam's avatar

Spatie Media Library / Image changes the colour/hue of converted photos

Hi There,

I'm using Laravel with Spatie Media Library to build a photography website. The Media Library is awesome! The media library in turn uses Spatie Image to manipulate the uploaded photos (resize to make thumbnails and smaller photos for mobile and tablet for example).

I have everything setup and it works well. My problem is that when I generate media conversions from my original photo (width 1920) the conversions look different. The pictures have a lot less colour in it, they look a lot more pale, for instance a lot of yellow gets pulled out. It feels like the hue and saturation gets lowered.

I have used both GD and Imagick (wow, to set that up on mac!) but the problem is the same with both drivers.

I have tried to generate the images with nonOptimized like this but it doesn't make a difference for the colour changes.

$this->addMediaConversion('1600')
         ->width(1600)
         ->nonOptimized();

I have upgraded to all the latest packages with 'composer update'

I have searched a lot on Laracasts, Stack Overflow and google but I can't find the solution to my problem. I feel like it's an optimization setting, but not sure.

Is there anybody out there who has encoutered this problem as well, or is there anybody who might have a clue what could be the cause, please let me know.

Many thanks in advance, Greetings Daan, from Amsterdam

0 likes
4 replies
DaanAmsterdam's avatar

Could very much be related. Thanks for pointing me in that direction. Doesn't solves my problem yet but might bring me closer to the solution.

click's avatar
click
Best Answer
Level 35

https://stackoverflow.com/questions/12815305/bad-cmyk-to-rgb-conversion-with-gd

GD doesn't support cmyk at all as far as I can read. And based on the stackoverflow of this ticket it looks like there is no way around it.

And I know Imagick also requires some extra task to copy the ICC Profile from the original image to the new image (your resized one). Leaving out this icc profile can distort the colors. I discovered this last week because I wanted to remove EXIF data from uploaded images and stumbled on this ticket: https://stackoverflow.com/questions/13646028/how-to-remove-exif-from-a-jpg-without-losing-image-quality

Maybe it can point you or the maintainers of the library into the good direction

DaanAmsterdam's avatar

Hi Click,

Thank you for your reply. Your comment led me in the direction of color spaces and ICC profiles.

I'm not sure about CMYK, but my designer gave me the test imagery photos in the proPhotoRGB color space, as exported by Adobe Lightroom. This was the cause of the problem, as apparently it's not possible to convert from proPhotoRGB to RGB for GD or Imagick without significant colour loss.

When we exported the photos from Lightroom in the sRGB color space, the problem was solved. sRGB is a smaller color space then proPhotoRGB, and therefore easier for the conversion engines to convert, without the colour loss.

There is still a change of ICC profile, now from sRGB to RGB. The difference is not a lot, at first sight it doesn't look like a loss. I will look into how to preserve the original ICC profile with either the GD library or Imagick. That could make the quality of the images even a bit better I think. My guess is this could be done with one of the Spatie packages already in use (Spatie Image or Spatie Image Optimizer).

Thanks again for your thoughts. Greets

1 like

Please or to participate in this conversation.