我尝试获取PNG文件的alpha值,使用的是imagepng()
函数。但是问题是alpha
只返回了0。
我的制作带有alpha的PNG文件的代码
$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透明度的代码
$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。