homepage Welcome to WebmasterWorld Guest from 184.72.69.79
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Pubcon Platinum Sponsor 2014
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
edzillion




msg:3672033
 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.

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




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

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

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