转自:https://blog.csdn.net/weixin_34126557/article/details/93468494
$type = exif_imagetype($srcimg);
switch($type) {
case 1:
$simg = imagecreatefromgif($srcimg);
break;
case 3:
$tmp = imagecreatefrompng($srcimg);
$w = imagesx($tmp);
$y = imagesy($tmp);
$simg = imagecreatetruecolor($w, $y);
$bg = imagecolorallocate($simg, 255, 255, 255);
imagefill($simg, 0, 0, $bg);
imagecopyresized($simg, $tmp, 0, 0, 0, 0,$w, $y, $w, $y);
break;
}