show png 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
apfelsaft
Forum Newbie
Posts: 2
Joined: Sun Jul 06, 2003 6:36 am

show png transparent

Post by apfelsaft »

hi i have a problem
i have a source picture and i write text on it and then i will show this new picture with a transparent background (backgroundcolor=black)
but it wont work
here is my code

Code: Select all

<?PHP 
Header("Content-type: image/png");
$width = 40; 
$height = 40; 
$color = '000000';
$font = 'FF0000';

function ImageHexColorAllocate(&$image,$hexstr) &#123; 
  return ImageColorAllocate($image,hexdec($hexstr&#1111;0].$hexstr&#1111;1]),hexdec($hexstr&#1111;2].$hexstr&#1111;3]),hexdec($hexstr&#1111;4].$hexstr&#1111;5])); 
&#125; 

$image = ImageCreate($width,$height); 
$org   = ImageCreateFromPNG( "picture.png" );
ImageCopy($image,$org,0,0,0,0,40,40);
ImageString($image,2,7,14,'text',ImageHexColorAllocate($image,$font ));
$trans = ImageColorTransparent($image,ImageHexColorAllocate($image,$color)); 
ImagePNG($image);
imagedestroy($image);
imagedestroy($org);
?>
but my background is still black instead of transparent
does anyone know why ?

please help
User avatar
Jean-Yves
Forum Contributor
Posts: 148
Joined: Wed Jul 02, 2003 2:13 pm
Location: West Country, UK

Post by Jean-Yves »

What browser are you using? IE seems to have difficulties with some transparent PNG's, though not all for some strange reason. Moz appears ok.

Not sure if that helps...
m3rajk
DevNet Resident
Posts: 1191
Joined: Mon Jun 02, 2003 3:37 pm

Post by m3rajk »

like he said, if you're using ie, don't call it a problem till you've tested it elsewhere. ie doesn't have full png support. microsoft doesn't like open source technologies
apfelsaft
Forum Newbie
Posts: 2
Joined: Sun Jul 06, 2003 6:36 am

Post by apfelsaft »

i got it now
i changed the script so that it creates a transparent image and copys a transparent source image on it
and i found out that it works with php 4.3.2 (gd libary 2.x) but not with php 4.2.3 (& older gd libary) which my websapceprovider uses
macewan
Forum Commoner
Posts: 97
Joined: Mon Jul 07, 2003 8:27 pm

Post by macewan »

Post Reply