我试着获得alpha
一个PNG.我正在这样做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);
Run Code Online (Sandbox Code Playgroud)
我的阅读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
Run Code Online (Sandbox Code Playgroud)
我不知道为什么它只返回0而不是1.
你应该调用imageAlphaBlending
和imageSaveAlpha
调用之前imagesetpixel
:
imageAlphaBlending($gd, false);
imageSaveAlpha($gd, true);
imagesetpixel($gd, 0,0, imagecolorallocatealpha($gd, 200,200,200,1));
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
355 次 |
最近记录: |