0

我已经查看了许多其他线程,人们遇到了 png 图像变黑的问题,它应该是透明的,并且没有一个解决方案对我有用。

也许我在代码中的其他地方出错了?也许我的网络服务器不支持 imagealhpableending?

感谢任何可以提供帮助的人。

        $photo = imagecreatefrompng( "{$thumb_folder}{$new_file_name}" );
        $width = imagesx($photo);
        $height = imagesy($photo);

        $new_width = 32;
        $new_height = floor($height / ($width / $new_width)); 

        $temp_photo = imagecreatetruecolor($new_width, $new_height);

        imagealphablending($temp_photo, false);

        imagesavealpha($temp_photo, true);

        $transparent = imagecolorallocatealpha($temp_photo, 255, 255, 255, 127);

        imagefilledrectangle($temp_photo, 0, 0, $new_width, $new_height, $transparent);

        imagecopyresampled($temp_photo, $photo, 0, 0, 0, 0, $new_width, $new_height, $width, $height);

        imagepng($temp_photo, "{$thumb_folder}{$new_file_name}" );
4

1 回答 1

0

无论如何,分配给图像的第一种颜色始终是背景颜色,因此无需绘制填充的矩形。从代码中删除它,看看你得到了什么。

于 2012-06-22T19:21:59.230 回答