Welcome to WebmasterWorld Guest from 54.160.131.144

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

problems with GD image transparency

imagecolorallocatealpha wont change all white pixels to alpha

     

edzillion

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.

<?php

$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");
imagepng($png);
?>

How do I do this?

edzillion

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

5+ Year Member



Fixed it:

<?php

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

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

?>

Worked fine. Thanks

 

Featured Threads

Hot Threads This Week

Hot Threads This Month