dqk42179 2011-03-15 00:55
浏览 166
已采纳

使用GD2将png转换为jpg ..透明度问题

I have an image.png with white background and some trasparceny over it.

I tried this to convert the image into jpg:

$data = file_get_contents('image.png');
$resource = imagecreatefromstring($data);
imagejpeg($resource); //> I TRIED WITH QUALITY = 100 TOO

Problem is where the png got the trasparency now the jpg got a pretty huge black zone. This is how jpg looks:

http://img861.imageshack.us/img861/20/context.jpg

Any way to solve the problem?

Edit1:

As suggested by Abiusx I tried this too:

$data = file_get_contents('image.png');
$resource = imagecreatefromstring($data);
imagealphablending($data, false);
imagesavealpha($data, true);
imagejpeg($resource);

But the result was the same. Please note The source .png image is:


(source: tipradar.com)

Thanks to Patrick comment: here the trick: GD! Converting a png image to jpeg and making the alpha by default white and not black

  • 写回答

2条回答 默认 最新

  • doujiao3074 2011-03-15 13:50
    关注
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 求解 yolo算法问题
  • ¥15 虚拟机打包apk出现错误
  • ¥30 最小化遗憾贪心算法上界
  • ¥15 用visual studi code完成html页面
  • ¥15 聚类分析或者python进行数据分析
  • ¥15 三菱伺服电机按启动按钮有使能但不动作
  • ¥15 js,页面2返回页面1时定位进入的设备
  • ¥50 导入文件到网吧的电脑并且在重启之后不会被恢复
  • ¥15 (希望可以解决问题)ma和mb文件无法正常打开,打开后是空白,但是有正常内存占用,但可以在打开Maya应用程序后打开场景ma和mb格式。
  • ¥20 ML307A在使用AT命令连接EMQX平台的MQTT时被拒绝