Quord Posted June 11, 2011 Share Posted June 11, 2011 I want to be able to change the color of a couple of my image layers, and I've tried multiple websites and have searched PHP.net, but to no avail. <?php $image = imagecreatefromgif('http://i53.tinypic.com/2dig2du.gif'); $index = imagecolorexact($image, 255, 0, 0); imagecolorset($image, $index, 0, 0, 0); imagepng($image); imagedestroy($image); ?> ERROR I receive: ‰PNG IHDRàè«I®»PLTEÿÿÿÌÌ _ŧtRNS@æØfaIDATxœíË1 0Ø¿¥ 4‚Ÿ lÿ"€w²W%˲,˲,˲,˲,˲,˲,˲,˲,˲,˲,˲,˲,˲,˲,˲,˲,˲|›€Åq€¤š•} IEND®B`‚ Now, I have the image url as 'box.gif' in my actual code -- I just uploaded it to tinypic so that you can access it. As you can see, the box has blue in the center and a thick white border on the outside. How do I identify the blue and change only that (to red or black for example)? OR: If I have an image that's only ONE color, how do I change that one color? I'm having the hardest time figuring it out. Thanks in advance for the help! Quote Link to comment https://forums.phpfreaks.com/topic/239041-change-gif-image-color/ Share on other sites More sharing options...
sunfighter Posted June 11, 2011 Share Posted June 11, 2011 Answer to your second query: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head> <title>New document</title> <meta name="generator" content="TSW WebCoder 2010" /> <script type="text/javascript"> function colorchange(){ document.getElementById('sq').style.backgroundColor = 'blue'; } </script> </head> <body style="background-color:white;"> <div id="sq" style="background-color:red;height:50px;width: 50px;"></div> <input type="button" value="Change" onclick="colorchange();" </body> </html> You should be able to do what you want by modifying this for your first question. Quote Link to comment https://forums.phpfreaks.com/topic/239041-change-gif-image-color/#findComment-1228335 Share on other sites More sharing options...
requinix Posted June 11, 2011 Share Posted June 11, 2011 That's not an error message. That's PNG image. Instead of using imagepng(), header("Content-Type: image/gif"); imagegif($image); Quote Link to comment https://forums.phpfreaks.com/topic/239041-change-gif-image-color/#findComment-1228513 Share on other sites More sharing options...
Quord Posted June 12, 2011 Author Share Posted June 12, 2011 Thanks for the help. The problem I'm having now is changing the full color of the image when it is anti-alias. I've already change FF0000 (255, 0, 0) to 000000 (0, 0, 0).. but how do I change each shade of red as well, keeping it anti-alias for whatever color I change it to? Problem Image: $watermark3 = imagecreatefromgif('base.gif'); $dest3 = imagecreatetruecolor(579, 605); imagecopy($dest3, $watermark3, 0, 0, 0, 0, 579, 605); imagecolorset ($watermark3, imagecolorexact ($watermark3, 255, 0, 0), 0, 0, 0); Quote Link to comment https://forums.phpfreaks.com/topic/239041-change-gif-image-color/#findComment-1228794 Share on other sites More sharing options...
requinix Posted June 12, 2011 Share Posted June 12, 2011 Since there are only for ($i = imagecolorstotal($image) - 1; $i >= 0; $i--) { $color = imagecolorsforindex($image, $i); if ($color["alpha"] == 0 && /* shade of red */) { imagecolorset($image, $i, /* red, green, blue */); } } Quote Link to comment https://forums.phpfreaks.com/topic/239041-change-gif-image-color/#findComment-1228819 Share on other sites More sharing options...
Quord Posted June 13, 2011 Author Share Posted June 13, 2011 Thanks, but if I'm pulling RGB from a database depending on each user (having a different one), how am I to know each different shade I want it changed to? Say Player 1 has RGB of 156, 39, and 4 and Player 2 has RGB of 29, 198, and 67. Is there a way for it to automatically detect the proper shades of each? Quote Link to comment https://forums.phpfreaks.com/topic/239041-change-gif-image-color/#findComment-1228875 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.