我有很多jpeg图像,我想用php转换成png图像。
这些jpeg文件将由客户端上传,所以我不能相信它们能确保格式正确。
我还想让他们的白色背景透明。
php有什么函数可以用来实现这一点吗?

最佳答案

在尝试了几天不同的解决方案并做了更多的研究之后,
这就是我发现对我有用的东西。

 $image = imagecreatefromjpeg( 'image.jpg' );
 imagealphablending($image, true);
 $transparentcolour = imagecolorallocate($image, 255,255,255);
 imagecolortransparent($image, $transparentcolour)

imagealphablending($image, true);很重要。
使用前一个答案中提到的imagesavealpha($f, true);显然不起作用,而且似乎实际上会阻止您使背景透明…
输出具有正确标题的透明图像。
<?php
     header( 'Content-Type: image/png' );
     imagepng( $image, null, 1 );
?>

07-24 09:50
查看更多