php png image transparency

Posted by user1334130 on Stack Overflow See other posts from Stack Overflow or by user1334130
Published on 2012-08-31T21:35:28Z Indexed on 2012/08/31 21:37 UTC
Read the original article Hit count: 131

Filed under:
|

I have been working with some code to draw a circle but I am having problems with removing the black background from the shape. I am using imagecopyresampled for its AA features in order to draw a smooth circle, so I can't use a different drawing function. Thanks.

<?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);

?>

© Stack Overflow or respective owner

Related posts about php

Related posts about drawing