php png图像透明度

时间:2012-08-31 21:35:29

标签: php drawing

我一直在使用一些代码画一个圆圈,但是我遇到了从形状中删除黑色背景的问题。我使用imagecopyresampled作为其AA功能,以绘制一个光滑的圆,所以我不能使用不同的绘图功能。谢谢。

<?php

$img_2 = imagecreatetruecolor(200, 200);

$red = imagecolorallocate($img_2, 255, 0, 0);
imagefill($img_2, 0, 0, $red);


//set circle values
$xPos = 50;
$yPos = 80;
$diameter = 40;

$img_1 = imagecreatetruecolor(($diameter + 2) * 2, ($diameter + 2) * 2);

$green = imagecolorallocate($img_1, 0, 255, 0);

//draw the circle
imagefilledarc($img_1, $diameter+1, $diameter+1, ($diameter + 2) * 2, ($diameter + 2) *      2, 0, 360, $green, IMG_ARC_PIE);
imagecopyresampled($img_2, $img_1, $xPos, $yPos, 0, 0, $diameter+2, $diameter+2, ($diameter + 2) * 2, ($diameter + 2) * 2);


header("Content-type: image/png");
imagepng($img_2);
imagedestroy($img_1);
imagedestroy($img_2);

?>

1 个答案:

答案 0 :(得分:0)

嗯,你可以这样做:

$img_1 = imagecreatetruecolor(($diameter + 2) * 2, ($diameter + 2) * 2);
imagesavealpha($img_1, TRUE);
imagefill($img_1, 0, 0, imagecolorallocatealpha($img_1, 255, 0, 0, 127));

或者这个:

$img_1 = imagecreatetruecolor(($diameter + 2) * 2, ($diameter + 2) * 2);
$red = imagecolorallocate($img_1, 255, 0, 0);
imagefill($img_1, 0, 0, $red);