0

I have to work with an image with PHP GD. The problem is when I copy the original picture, the colors are not the same.

original Picture :

OriginalPicture

People told me to convert my jpg into sRGB profil instead AdobeRPG.

So I did it:

    $image = new Imagick($chemin_image);

// On enleve tout les profils qu'il y avait à la base
$image->profileImage('*' , false);

// Essayer de mettre en SRGB si ce n'est pas le cas
$icc_srgb = file_get_contents('../../admin-cache/profil_icc/sRGB_IEC61966-2-1_black_scaled.icc');

$image->profileImage('icc' , $icc_srgb);
$image->transformImageColorspace(13);

$image->writeImage($chemin_image);

I know that not the same size and the same quality, is normal.

That work, the color are the same, but now is not the same contraste :

ConvertedImage

I went to Facebook, to see, how he does in his own upload system, I tried with my picture and it's work very well, but i have no idea how they have done.

  • Using `PHP 7.0.13` I can `imagecopyresized()` your original image and output it with no change to the colours. So, what is your original problem (not the problem after using `imagick`)? Do you want to resize/crop/rotate the image? And what version of PHP are using? – timclutton Dec 08 '16 at 16:47
  • The problem it's you can do it but it's not in sRGB profil.. I solve it and answered my question. Thank you for you help. – KEVIN LOURENCO Dec 14 '16 at 12:52

1 Answers1

0

The doc of php is not totaly correct, do not use transformImageColorspace for do this stuff.

function ConvertirProfilEnSRGB($chemin_image){
    if(class_exists('Imagick')) {
            $final_image = new Imagick($chemin_image);

            // Add profil 
            $icc_srgb = file_get_contents('profil_icc/sRGB_v4_ICC_preference.icc');

            $final_image->profileImage('icc', $icc_srgb);

            // On va écrire l'image à la fin
            $final_image->writeImage($chemin_image);
        }
}

Find sRGB_v4_ICC_preference.icc here :

sRGB profiles

If you want to create image with GD (for resize per exemple), in order to convert in sRGB without change all your code, you have to convert with the code above the original picture and the final picture :

$pathToFile = $_FILES['myfile']['tmp_name'];

// First convert of original image
ConvertirProfilEnSRGB($pathToFile) ;
// GD with true color for best colors 
$ImageChoisie = @imagecreatefromjpeg($pathToFile);

// Some code ...
// truecolor...

// Create final image 
imagejpeg($ImageChoisie, $pathToFinalFile, 80);
// Add sRGB to final image
ConvertirProfilEnSRGB($pathToFinalFile) ;

I hope this will help you.