Welcome to WebmasterWorld Guest from

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

problems with GD image transparency

imagecolorallocatealpha wont change all white pixels to alpha



11:58 am on Jun 11, 2008 (gmt 0)

5+ Year Member

Basically what I want to do is change all the white pixels in a png image to transparent. Found this code somewhere, which seems to make most of the white pixels transparent, but not all.


$png = imagecreatefrompng("top.png");
imagesavealpha($png, true);

$trans_colour = imagecolorallocatealpha($png, 255, 255, 255, 127);
imagefill($png, 0, 0, $trans_colour);

header("Content-type: image/png");

How do I do this?


12:05 pm on Jun 11, 2008 (gmt 0)

5+ Year Member

Fixed it:


header("Content-type: image/png");
$im = imagecreatefrompng("top.png");
imagesavealpha($im, true);

$bg_color = imagecolorat($im,1,40);
imagecolortransparent($im, $bg_color);


Worked fine. Thanks


Featured Threads

Hot Threads This Week

Hot Threads This Month