Page 1 of 1
image - transparent
Posted: Wed Jun 07, 2006 10:31 pm
by tecktalkcm0391
How do you make PHP make a jpeg image background transparent?
Re: image - transparent
Posted: Wed Jun 07, 2006 10:37 pm
by alex.barylski
tecktalkcm0391 wrote:How do you make PHP make a jpeg image background transparent?
You can't...JPEG doesn't support transparent backgrounds
You have to use either GIF or PNG or use a mask on your JPEG which is unessecary (and useless in IMG tags) when you can just use PNG...
PNG is the better choice...
IE doesn't render PNG properly but I believe it's fixed in IE7...however search google as I believe there is a hack you can use to correct this issue
Cheers

Posted: Wed Jun 07, 2006 10:38 pm
by tecktalkcm0391
Yeah, I just thought about that, well how could you do it if the image was a gif or png?
Posted: Thu Jun 08, 2006 4:55 am
by bitbytes
am looking into it . thanks
Posted: Thu Jun 08, 2006 5:07 am
by onion2k
Posted: Thu Jun 08, 2006 6:18 am
by bokehman
It is also possible to make a transparent 8 bit (palette image) .png. This will be one third the filesize and smaller than a comparitive .gif image. Also if the transparency is single channel, full transparency (127), the image should work fine in IE. If you are going to use less than 256 colours go for the 8 bit format.
Code: Select all
<?php
$image = imagecreate(200, 200);
$transparent_red = ImageColorAllocateAlpha($image, 255, 0, 0, 127);
imagefill($image, 0, 0, $transparent_red);
header("Content-type: image/png");
imagepng($image);
?>