Codice PHP:
<?
$img = imagecreatefromgif("PZE0832220053G.001.gif");
imagepng($img, "image.png");
imagedestroy($img);
function html2rgb($input)
{
$input=($input[0]=="#")?substr($input, 1,6):substr($input, 0,6);
return array(
'r'=>hexdec( substr($input, 0, 2) ),
'g'=>hexdec( substr($input, 2, 2) ),
'b'=>hexdec( substr($input, 4, 2) )
);
}
function colorReplace($image,$oldcolor,$newcolor=false)
{
//make the colors rbg
$rgbold = html2rgb($oldcolor);
//make the old color transparant
$oldcolor = imagecolorallocate($image, $rgbold[r], $rgbold[g], $rgbold[b]);
imagecolortransparent($image, $oldcolor);
if($newcolor)
{
$rgbnew = html2rgb($newcolor);
//make a new image in the new color
$newimage = imagecreatetruecolor(imagesx($image), imagesy($image));
//color the new image
$newcolor = imagecolorallocate($image,$rgbnew[r], $rgbnew[g], $rgbnew[b]);
imagefill($newimage, 0, 0, $newcolor);
//paste the old image on the new colored image
imagecopymerge($newimage,$image,0,0,0,0, imagesx($image), imagesy($image), 100);
imagecopymerge($image,$newimage,0,0,0,0, imagesx($image), imagesy($image), 100);
imagedestroy($newimage);
}
}
header("Content-type: image/gif");
$img3 = imagecreatefrompng("image.png");
colorReplace($img3,"ffffff","93A3A0");
imagegif($img3);
imagedestroy($img3);
?>