Codice PHP:
<?
$filename = 'image.gif';
list($width, $height) = getimagesize($filename);
$new_width = 600;
$new_height = 600;
$image_p = imagecreatetruecolor($new_width, $new_height);
$image = imagecreatefromgif($filename);
imagecopyresampled($image_p, $image, 0, 0, 0, 0, $new_width, $new_height, $width, $height);
imagepng($image_p, "image.png", 9);
imagedestroy($image_p);
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);
}
}
$imgg = imagecreatefrompng("image.png");
colorReplace($imgg,"ffffff","93A3A0");
imagegif($imgg, "image.gif");
imagedestroy($imgg);
?>