Codice PHP:
if ($old_ext=="GIF"){
$tpcolor=imagecolorat($source, 0, 0);
// in the real world, you'd better test all four corners, not just one!
imagepalettecopy($thumb2, $source);
imagecopyresized($thumb2, $source, 0, 0, 0, 0,THUMB_WIDTH_SCHEDA,$thumbHeightScheda,$width,$height);
$pixel_over_black = imagecolorat($thumb2, 0, 0);
// ...but now make the fill white...
$bg = imagecolorallocate($thumb2, 255, 255, 255);
imagefilledrectangle($thumb2, 0, 0, THUMB_WIDTH_SCHEDA, $thumbHeightScheda, $bg);
imagecopyresized($thumb2, $source, 0, 0, 0, 0, THUMB_WIDTH_SCHEDA, $thumbHeightScheda, $width, $height);
$pixel_over_white = imagecolorat($thumb2, 0, 0);
// ...to test if transparency causes the fill color to show through:
if($pixel_over_black != $pixel_over_white){
// Background IS transparent
imagefilledrectangle($thumb2, 0, 0, THUMB_WIDTH_SCHEDA, $thumbHeightScheda, $tpcolor);
imagecopyresized($thumb2, $source, 0, 0, 0, 0, THUMB_WIDTH_SCHEDA, $thumbHeightScheda, $width, $height);
imagecolortransparent($thumb2, $tpcolor);
}
}