PHP把PNG图片转化为JPG时透明背景变黑色

$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;
}

 

posted @ 2018-06-19 09:46  Basu  阅读(1757)  评论(0编辑  收藏  举报