imagefill只填充图像背景的一半?

时间:2014-01-16 22:34:43

标签: php image

imagefill只填充了图像背景的一半?

有人有任何想法吗?

$img = imagecreatefrompng($current);
$kek=imagecolorallocate($img, 255, 255, 255);
imagefill($img,0,0,$kek);
imagejpeg($img,$new,70);
imagedestroy($img);

Example Example

1 个答案:

答案 0 :(得分:0)

imagefill对图像执行Flood-Fill算法,与paint中的bucket fill相同。所以继续填充直到该区域关闭,并且将停止填充。 您应该将原始图像复制到较大的画布中,然后执行图像填充,然后裁剪图像以恢复原始尺寸:

$img = imagecreatefrompng($current);
$width=imagesx($img);
$height=imagesy($img);
$newimg=imagecreatetruecolor($width+2,$height+2);//1 pixcel larger from each side
imagecopy($newimg,$img,1,1,0,0,$width,$height);
$kek=imagecolorallocate($img, 255, 255, 255);
imagefill($img,0,0,$kek);
imagecopy($img,$newimg,0,0,1,1,$width-2,$height-2);//back to the original size
imagejpeg($img,$new,70);

我没有测试代码,但我认为应该没问题。

相关问题