Jump to content

Recommended Posts

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!

Link to comment
https://forums.phpfreaks.com/topic/239041-change-gif-image-color/
Share on other sites

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.

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:

s4bcjk.png

 

$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);

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 */);
    }
}

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?

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.