Converting an image to transparent

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
OutCaster
Forum Newbie
Posts: 2
Joined: Tue Jan 16, 2007 5:47 pm

Converting an image to transparent

Post 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.
User avatar
Kieran Huggins
DevNet Master
Posts: 3635
Joined: Wed Dec 06, 2006 4:14 pm
Location: Toronto, Canada
Contact:

Post 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.
User avatar
jayshields
DevNet Resident
Posts: 1912
Joined: Mon Aug 22, 2005 12:11 pm
Location: Leeds/Manchester, England

Post 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.
OutCaster
Forum Newbie
Posts: 2
Joined: Tue Jan 16, 2007 5:47 pm

Post by OutCaster »

Thanks. I'll try the PHPGd forum. I can't do it in photoshop because I'm trying to generate it dynamically.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post 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.
Post Reply