看起来像是卷积代码中的错误(角点在某些实现中是特殊情况)。
作为解决方法,您可以在卷积之前保存该角的像素值并在之后恢复它,使用imageSetPixel()
.
您需要保存的像素位于 (0,0),并且可能您还需要检查透明度(但我认为它应该只适用于imageColorAt
and imageSetPixel
).
测试代码
文件“giants.png”是我从您上面发布的文件中获取的。如果我不使用imageSetPixel
我体验到了与你相同的额外像素。和imageSetPixel
,图像对我来说看起来是正确的。
我运行的顺序可能略有不同ImageSaveAlpha
或设置 alpha 混合。
<?php
$giants = ImageCreateFromPNG('giants.png');
$imageResource = ImageCreateTrueColor(190, 190);
ImageColorTransparent($imageResource, ImageColorAllocateAlpha($imageResource, 0, 0, 0, 127));
ImageAlphaBlending($imageResource, False);
ImageSaveAlpha($imageResource, True);
ImageCopyResampled($imageResource, $giants, 0, 0, 0, 0, 190, 190, ImageSX($giants), ImageSY($giants));
$color = ImageColorAt($imageResource, 0, 0);
ImageConvolution($imageResource, array(
array( -1, -1, -1 ),
array( -1, 16, -1 ),
array( -1, -1, -1 ),
), 8, 0);
ImageSetPixel($imageResource, 0, 0, $color);
ImagePNG($imageResource, 'dwarves.png');
?>