Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP GD - Transparent areas goes black

Tags:

php

image

iso

gd

I am trying to make very simple ISO engine in PHP, my attempts to render in correct place, order etc are succeding however the images drawn, for some reason are black where it should be transparent. PNG files have transparency channel and I am using following test code: http://pastebin.com/TXk4LkJ8 The code is just rough draft.

Files are just 3 faces of an block with dimensions as follows: top - 44x22; sides:23x34

Thank you for your help and I hope the question is clear enough.

Edit: Here is the problem: http://dl.dropbox.com/u/10530011/obrazki/isofail.png

Edit: [SOLVED] For some reason I had to save the images as GIF to make it work. Thank you for your help.

like image 256
Sebi Avatar asked May 06 '11 15:05

Sebi


People also ask

Why does my transparent image have a black background?

The default background is black, so your transparency will look black unless there is anything behind it or you change the background. The PNG is absolutely transparent. There were PNGs that i had imported before without any problem. I used to get the transparency.

Why is my transparent PNG black?

If your PNG image is saved with a transparent background, it will appear with a black background in Brainshark. That is because transparency in images is not supported in Brainshark. As a workaround, you can either add in a plain background using an image editing program, or try to save the image as a JPG or GIF.

How do I get rid of black background in PNG?

When a PNG image with a transparent background is selected from the Recent FIle selector and appears with a black background, the black background can be removed by re-uploading the image as a New File each time you use the image.


1 Answers

You should call these two functions before saving the png image, imagealphablending() and imagesavealpha():

imagealphablending( $image, false );
imagesavealpha( $image, true );
like image 103
Paolo Stefan Avatar answered Sep 28 '22 08:09

Paolo Stefan