Forum Moderators: coopster

Message Too Old, No Replies

Problem with imagecolortransparent() Function

         

ntbgl

9:20 am on Jul 23, 2008 (gmt 0)

10+ Year Member



I am at a loss.

I'm trying to create a transparent color, but it's coming back black. (The color I'm trying to turn transparent).

Here's my script:

<?php
header("Content-type: image/png");

$img=imagecreate(2000,20);

$background=imagecolorallocate($img,0,0,0);

$pink=imagecolorallocate($img,255,0,132);

imagearc($img,19,0,41,41,90,270,$pink);
imagearc($img,1978,0,41,41,270,90,$pink);
imagefill($img,1,19,$pink);
imagefill($img,1999,19,$pink);

imagecolortransparent($img,imagecolorallocate($img,0,0,0));

imagepng($img);
imagedestroy($img);
?>

Sekka

9:39 am on Jul 23, 2008 (gmt 0)

10+ Year Member



Possibly a daft question, but when do you actually fill the image with a background colour?

And you should be able to do,

imagecolortransparent($img,$background);

ntbgl

10:10 am on Jul 23, 2008 (gmt 0)

10+ Year Member



I've tried that, but with the same affect.

henry0

11:16 am on Jul 23, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



did you try using
imagecreatefrompng();

your GD is GD2 isn't it?

Is your php > 4.3.3? a bug was reported in 4.3.3

ntbgl

12:53 pm on Jul 23, 2008 (gmt 0)

10+ Year Member



I'm confused, isn't imagecreatefrompng() used for important png file? I'm creating an image from scratch.

I'm using PHP version 5.2.6

mrscruff

1:50 pm on Jul 23, 2008 (gmt 0)

10+ Year Member



Hello,

Try this :)

<?php
header("Content-type: image/png");

$img=imagecreate(2000,20);

$background=imagecolorallocate($img,0,0,0);

imagecolortransparent($img,$background);

$pink=imagecolorallocate($img,255,0,132);

imagearc($img,19,0,41,41,90,270,$pink);
imagearc($img,1978,0,41,41,270,90,$pink);
imagefill($img,1,19,$pink);
imagefill($img,1999,19,$pink);

imagepng($img);
imagedestroy($img);
?>

call imagecolortransparent() before the second imagecolorallocate().

ntbgl

11:52 am on Jul 24, 2008 (gmt 0)

10+ Year Member



Thank you so much, it worked great!