image color transparent

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
kevin_javia
Forum Newbie
Posts: 15
Joined: Mon May 24, 2004 9:46 am
Location: India
Contact:

image color transparent

Post by kevin_javia »

Hi I am using following code to make the a color transparent in an image.

Code: Select all

<?php

header ("Content-type: image/png");
$im = imagecreate(500, 400);

$bgc = imagecolorallocate($im, 0, 0, 0);        
$tc = imagecolorallocate($im, 255, 255, 255);     

imagettftext($im, 20, 10, 100, 200, $tc, "/arial.ttf",$text);
imagecolortransparent($im, $bgc);
imagepng($im,"images/test.png");
imagedestroy($im); 

?>
What I am getting is an image with black background with white text. I want to remove the black background.

Can any body help me with this?

Tanks a ton in advance.
Kevin.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

are you using IE to view it? IE has non-standard support for transparency in PNG files.
User avatar
kevin_javia
Forum Newbie
Posts: 15
Joined: Mon May 24, 2004 9:46 am
Location: India
Contact:

Post by kevin_javia »

I even tried the JPEG functions but the results were similar. :(
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

since JPEG doesn't support transparency at all, I wouldn't think it'd make a difference.
User avatar
vigge89
Forum Regular
Posts: 875
Joined: Wed Jul 30, 2003 3:29 am
Location: Sweden

Post by vigge89 »

save the outputted image, and then open it up in an image previewing program. if it's transparent where it should be, then it's IEs lacking of support which's the problem
User avatar
kevin_javia
Forum Newbie
Posts: 15
Joined: Mon May 24, 2004 9:46 am
Location: India
Contact:

Post by kevin_javia »

I did view the outputed image in ACDC and other programs. There is no transparent portion in the whole image.

That means this is not IEs problem I guess. Can any body throw some light on this topic?

Thanks vigge n feyd.

Kevin.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

the only "quick" way to tell if it really has transparency or not, is not through most image viewing programs.. but through a browser known to support it correctly and simply. Create an html with a repeating black and white square background, and place the image into the body. If it continues to not work, then yes, there is a problem.
Post Reply