0
我想编码的东西,我可以将图像叠加在一起,并将它们输出为1图像。此外,我也可以将其中的一幅图像向下移动20像素和10像素。我已经做好了一切,并设定了我想要的方式,但唯一的问题是,当我将其中一幅图像向右移动时,它显示了左侧的黑点,我如何才能将它全部透明化。即使图像被移位? ?PHP GD Image问题
<?php
$layers = array();
$shiftx = array();
$shifty = array();
$wid = array();
$hei = array();
$layers[] = imagecreatefrompng("egg.png");
$shiftx[] = "0";
$shifty[] = "0";
$wid[] = "75";
$hei[] = "75";
$layers[] = imagecreatefrompng("fedora.png");//Top Layer
$shiftx[] = "-20";
$shifty[] = "0";
$wid[] = "56";
$hei[] = "56";
$image = imagecreatetruecolor(100, 100);
$transparent = imagecolorallocatealpha($image, 255, 255, 255, 127);
imagefill($image, 0, 0, $transparent);
//Will merge the layers into one image//
for ($i = 0; $i < count($layers); $i++)
{
$y=$shifty[$i];
$x=$shiftx[$i];
$w=$wid[$i]-$shiftx[$i];
$h=$hei[$i]-$shifty[$i];
imagecopy($image, $layers[$i], 0, 0, $x, $y, $w, $h);
}
//Everything is now done, except for the image output. We will do this now.//
header('Content-type: image/png');
imagealphablending($image, false);
imagesavealpha($image, true);
imagepng($image);
imagedestroy($image);
>
我遇到的问题是,例如,当我把在-20移位(这样它会向右移20),并将图像更改为+20,它显示为左侧黑色。前20个像素是黑色的,但其余的都是透明的。为什么会这样做? – John
你需要imagealphablend()我认为 –