我认为你走错了方向,如果你试图让透明图像出现在颜色的顶部,那么你需要先填充然后复制图像。
另外,如果使用透明度,则需要调用ImageCreateTrueColor();而不是ImageCreate();
private function GenerateImage()
{
$original = imagecreatefrompng($this->ImagePath());
$x = imagesx($original);
$y = imagesy($original);
$image = imagecreatetruecolor($x,$y);
imagealphablending($image,true);
imagesavealpha($image,true);
$colour = imagecolorallocate($image,$this->RGB[0],$this->RGB[1],$this->RGB[2]);
imagefill($image,0,0,$colour);
imagecopyresampled($image,$original,0,0,0,0,$x,$y,$x,$y);
return imagepng($image,$this->GeneratedPath());
imagedestroy($original);
imagedestroy($image);
}
如果要在图像顶部绘制红色,请使用ImageFilledRectangle()而不是ImageFill()。出于某种原因,ImageFill似乎不能很好地处理透明胶片。
// Replace
imagefill($image,0,0,$colour);
// With
imagefilledrectangle( $image, 0,0, $x,$y,$colour);