我试图保持图像的透明度,如果有任何重新采样后但仍然会以黑色背景返回? $ image_copy是新图像,之后会显示。
$new_width = round($new_width, 0);
$new_height = round($new_height, 0);
$image_r = imagecreatetruecolor( $new_width, $new_height );
imagealphablending( $image_r, false );
imagesavealpha( $image_r, true );
imagecopyresampled( $image_r, $image, 0, 0, 0, 0, $new_width, $new_height, $image_width, $image_height);
imagedestroy($image);
if ($new_width > $width) $offset_width = ($new_width - $width) / 2;
if ($new_height > $height) $offset_height = ($new_height - $height) / 2;
$image_copy = imagecreatetruecolor($width, $height);
imagecopy($image_copy, $image_r, 0, 0, $offset_width, $offset_height, $width, $height);
imagedestroy($image_r);
imagepng($image_copy,"{$filename}.png", 9)
任何帮助都会很棒?
答案 0 :(得分:0)
也许您想查看此链接,希望它会有所帮助
How to keep transparent background on PNG when resizing with PHP?