Page 1 of 1

Converting an image to transparent

Posted: Tue Jan 16, 2007 5:52 pm
by OutCaster
Hi,

I have an image with a black background that I'd like to have converted to transparent image with the black part being transparent.

Code: Select all

$srcimg= imagecreatefromjpeg($newname2);
$black = imagecolorallocate($srcimg, 0, 0, 0);
imagecolortransparent($srcimg, $black);
That's the code I have so far. So basically I create the image, exact the black color using imagecolorallocate, and make the black part of the image transparent. It isn't working. What am I missing? I don't want to overlay it over any images right now. I'd like to have the image be transparent at all times. PNG format would be better.

Posted: Tue Jan 16, 2007 5:57 pm
by Kieran Huggins
you won't get the output you're expecting - especially from a jpeg.

Take it into photoshop... even if you can't get a good result, you'll have a better understanding of why you can't do it.

Posted: Tue Jan 16, 2007 6:58 pm
by jayshields
I'd bet onion2k would have an idea or teo for you if you posted this in the PHPGD forum. It can be done, only it might not look perfect, depending on the image ofcourse. If it's a one-off image change, like Kieran said, do it in your favourite image editor instead.

Posted: Wed Jan 17, 2007 9:26 am
by OutCaster
Thanks. I'll try the PHPGd forum. I can't do it in photoshop because I'm trying to generate it dynamically.

Posted: Wed Jan 17, 2007 9:32 am
by feyd
There's no need to create another thread, onion2k reads this board too. Just have some patience and he may choose to answer.