ladymeow Posted November 15, 2007 Share Posted November 15, 2007 I'm trying to come up with a script that will change the color of a transparent png to a new color. Like #FF0000 to #0000FF. The images I'm using are solid color with a transparent background. Anyways it's not going so well. I have this script that works for palpated images but when I try to use it with an image that has alpha transparency it gets all weird on me and shows up as solid blocks of color. <?php $pic = imagecreatefrompng("base.png"); $colorToChange = "FF0000"; $newColor = "0000FF"; $c1 = sscanf($colorToChange,"%2x%2x%2x"); $c2 = sscanf($newColor ,"%2x%2x%2x"); $cIndex = imagecolorexact($pic,$c1[0],$c1[1],$c1[2]); imagecolorset($pic,$cIndex,$c2[0],$c2[1],$c2[2]); header("Content-Type: image/png"); imagepng($image); imagedestroy($image); ?> I want to be able to change the color of a png image that has alpha transparency so that I can keep the soft line rather then having a pixilated edge. Is this even possible to do with PHP? Please help point me in the right direction. I'm very new to GD and PHP. Quote Link to comment Share on other sites More sharing options...
gerkintrigg Posted November 15, 2007 Share Posted November 15, 2007 Could you not isolate the alpha channel value for each pixel and turn it up to 100%. If the alpha value is less than 50% (for example) then replace the colour with white at 100%? Then create a loop to do this for every pixel and you'll have a new image that you could create as a JPG if necessary. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.