Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/powershell/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
php中的去交错png_Php_Gd - Fatal编程技术网

php中的去交错png

php中的去交错png,php,gd,Php,Gd,我尝试使用php函数对png图片进行逐行扫描 我在某处找到了导致此解决方案的提示: $img = imagecreatefrompng("interlaced.png"); imageinterlace($img, 0); $black = imagecolorallocate($img, 0,0,0); imagecolortransparent($img, $black); imagepng($img, "deinterlaced.png"); 不幸的是,这不仅会保持透明区域,而且会在图

我尝试使用php函数对png图片进行逐行扫描

我在某处找到了导致此解决方案的提示:

$img = imagecreatefrompng("interlaced.png");

imageinterlace($img, 0);
$black = imagecolorallocate($img, 0,0,0);
imagecolortransparent($img, $black);
imagepng($img, "deinterlaced.png");
不幸的是,这不仅会保持透明区域,而且会在图片使用真正的黑色时扩展它们

是否有另一种不使用imagecolorallocate进行逐行扫描的可能性

我已经尝试过使用imagesavealpha,但它不起作用,或者我用错了:

$img = imagecreatefrompng("interlaced.png");

imagealphablending($png, false);
imagesavealpha($png, true);

imageinterlace($img, 0);
imagepng($img, "deinterlaced.png");

这会导致所有透明区域均为黑色(这可能是原因,我当时选择imagecolortransparent中的rgb0,0,0的原因)

您的第二个代码块可以正常工作,但有一个小错误
imagealphabling
imagesavealpha
被传递到不正确的资源,即
$png
而不是
$img

更正代码:

$img = imagecreatefrompng("interlaced.png");

imagealphablending($img, false);
imagesavealpha($img, true);

imageinterlace($img, 0);
imagepng($img, "deinterlaced.png");

真烦人,我没看到。只是一个愚蠢的复制粘贴错误。感谢您指出,我离解决方案如此之近。