If you want to put a white background instead of black background, add this piece of code :
$path_parts = pathinfo($file);
if ($path_parts[‘extension’]==’gif’)
{
$img = imagecreatefromgif($file);
$imgr = imagecreatetruecolor($neww, $newh);
$bgc = imagecolorallocate ($imgr, 255, 255, 255);
imagefilledrectangle ($imgr, 0, 0, $neww, $newh, $bgc);imagecopyresampled($imgr, $img, 0, 0, 0, 0, $neww, $newh, $pixw, $pixh);
}