我尝试使用 php gdlib 在现有图像中将灰色(rgb:235,235,240)变为透明。
这是我使用的代码:
<?php
header("Content-type:image/png");
$picture = imagecreatefrompng("test.png");
$grey = imagecolorallocate($picture, 235, 235, 240);
imagecolortransparent($picture, $grey);
imagepng($picture);
imagedestroy($picture, "newpicture.png");
?>
当 test.png 上有很多不同的颜色时,此代码将不起作用。否则,当 test.png 上只有少量颜色时,此代码可以完美运行。为什么?