image - transparent
Moderators: onion2k, General Moderators
- tecktalkcm0391
- DevNet Resident
- Posts: 1030
- Joined: Fri May 26, 2006 9:25 am
- Location: Florida
image - transparent
How do you make PHP make a jpeg image background transparent?
-
alex.barylski
- DevNet Evangelist
- Posts: 6267
- Joined: Tue Dec 21, 2004 5:00 pm
- Location: Winnipeg
Re: image - transparent
You can't...JPEG doesn't support transparent backgroundstecktalkcm0391 wrote:How do you make PHP make a jpeg image background transparent?
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
- tecktalkcm0391
- DevNet Resident
- Posts: 1030
- Joined: Fri May 26, 2006 9:25 am
- Location: Florida
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);
?>