当我使用imagepng()做到这一点,我尝试获得一个PNG的alpha.
我的问题是alpha返回0.
我的代码为使PNG与alpha
$x = 1;
$y = 1;
$gd = imagecreatetruecolor($x, $y);
imagesetpixel($gd, 0,0, imagecolorallocatealpha($gd, 200,200,200,1));
imageAlphaBlending($gd, false);
imageSaveAlpha($gd, true);
imagepng($gd,"test.png");
imagedestroy($gd);
我的代码读PNG alpha
$im = imagecreatefrompng("test.png");
$rgb = imagecolorat($im, 0, 0);
$colors = imagecolorsforindex($im, $rgb);
$red = (int) $colors["red"];
$blue = (int) $colors["blue"];
$green = (int) $colors["green"];
$alpha = (int) $colors["alpha"]; // return only 0
我不知道为什么只返回0而不是1.