使用PHP将adobeRGB图片转换为sRGB后,如何获得与原点相同的图像

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.

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.