使用PHP的GDlib imagecopyresampled时,是否可以保留PNG图像透明度?
以下PHP代码段使用GD将浏览器上传的PNG大小调整为128x128。它的效果很好,除了原始图像中的透明区域在我的情况下被替换为纯黑色。
虽然imagesavealpha
已经确定,但事情并不完全正确。
保留重采样图像透明度的最佳方法是什么?
$uploadTempFile = $myField[ 'tmp_name' ]list( $uploadWidth, $uploadHeight, $uploadType ) = getimagesize( $uploadTempFile );$srcImage = imagecreatefrompng( $uploadTempFile ); imagesavealpha( $targetImage, true );$targetImage = imagecreatetruecolor( 128, 128 );imagecopyresampled( $targetImage, $srcImage, 0, 0, 0, 0, 128, 128, $uploadWidth, $uploadHeight );imagepng( $targetImage, 'out.png', 9 );
泛舟湖上清波郎朗
温温酱