J'essaye de recolorer une image png d'une couleur en utilisant la bibliothèque gd. J'ai trouvé un code dans un autre post qui va recolorer un gif. J'ai modifié ce code pour travailler avec png transparent. Voici mon code. Je peux créer un nouveau fichier png avec ce code mais la couleur n'est pas modifiée. S'il vous plaît, quelqu'un m'aide à changer de couleur dans un png transparent.Changer la couleur dans un png transparent de couleur unique en utilisant le libarary gd
<?php
// first we will create a transparent image. an image that has no color.
$width = 300; $height=340;
$image = imagecreatetruecolor($width,$height); //black image of the specified width x height.
imagealphablending($image, false); // set blend mode to false.
$col=imagecolorallocatealpha($image,255,255,255,127); // fill color
imagefilledrectangle($image,0,0,$width,$height,$col);
imagealphablending($image,true);
$shirt = imagecreatefrompng("shirt.png");
$color = imagecolorclosest ($shirt, 255,0,0);
imagecolorset($shirt,$color,92,92,92); // SET NEW COLOR
imagecopy($image, $shirt, 0, 0, 0, 0, $width, $height);
imagealphablending($image,true);
imagealphablending($image,false);
imagesavealpha($image,true);
if(imagepng($image, "hello.png", 1)){
echo "hello.png";
}
imagedestroy($image);
imagedestroy($shirt);
?>