小尺寸png背景变黑色

$path = "D:\\pic\\";
korea_process_avatar($path . 'smile1.png',$path . 'kk.png');

function korea_process_avatar($avatar = '', $destfile = '') {
        $filename = @imagecreatefrompng($avatar);
        $width = ImageSx($filename);
        $height = ImageSy($filename);
        $new_width = 10;
        $new_height = 10;
        $image_p = @imagecreatetruecolor($new_width, $new_height);
        @imagealphablending($image_p, false);
@imagesavealpha($image_p, true);
@imagealphablending($filename, false);
@imagesavealpha($filename, true);       
//生成尺寸小的png图片,背景会变黑,函数bug
        @fastimagecopyresampled($image_p, $filename, 0, 0, 0, 0, $new_width, $new_height, $width, $height);
//改为本函数即可解决
        @imagecopyresampled($image_p, $filename, 0, 0, 0, 0, $new_width, $new_height, $width, $height);
       
        imagepng($image_p, $destfile, 3);
        imagedestroy($image_p);
        imagedestroy($image);
    }

你可能感兴趣的:(小尺寸png背景变黑色)