homepage Welcome to WebmasterWorld Guest from
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member

Visit PubCon.com
Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

problems with GD image transparency
imagecolorallocatealpha wont change all white pixels to alpha

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

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)

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

Global Options:
 top home search open messages active posts  

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved