php 中的去隔行 png
deinterlace png in php
我尝试使用 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的原因)
你的第二个代码块可以正常工作,但有一个小错误; imagealphablending
和 imagesavealpha
传递了不正确的资源,即 $png
而不是 $img
。
更正后的代码:
$img = imagecreatefrompng("interlaced.png");
imagealphablending($img, false);
imagesavealpha($img, true);
imageinterlace($img, 0);
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的原因)
你的第二个代码块可以正常工作,但有一个小错误; imagealphablending
和 imagesavealpha
传递了不正确的资源,即 $png
而不是 $img
。
更正后的代码:
$img = imagecreatefrompng("interlaced.png");
imagealphablending($img, false);
imagesavealpha($img, true);
imageinterlace($img, 0);
imagepng($img, "deinterlaced.png");