【问题标题】:Transparent PNG Going Black透明PNG变成黑色
【发布时间】:2012-06-25 03:21:03
【问题描述】:

我已经查看了很多其他线程,有人遇到了 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}" );

【问题讨论】:

    标签: php png transparent alpha


    【解决方案1】:

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

    【讨论】:

      猜你喜欢
      • 2020-04-14
      • 1970-01-01
      • 2013-11-25
      • 2015-04-20
      • 2014-11-12
      • 2013-03-17
      • 1970-01-01
      • 2014-06-17
      • 2011-05-27
      相关资源
      最近更新 更多