Jump to content

Recommended Posts

This is my first time using GD. I've got an image with a transparent background. All the other pixels are the identical color (#8bc4ed). I want to replace all those pixels with a given color, say #CCC5AC. Here's my code that doesn't work yet:

 

$filepath = $_SERVER['DOCUMENT_ROOT'] . "/images/source_image.gif"; 
$image = imagecreatefromgif($filepath); 

$indexToSearchFor = imagecolorat($image, 3, 0); 
imagecolorset($image, $indexToSearchFor, 204, 197, 172); 

$filepath = $_SERVER['DOCUMENT_ROOT'] . "/images/target.gif"; 
imagegif ($image,  $filepath);

 

The output image is identical to the input image - no color is replaced.

 

What is the correct way to do this?

 

Here is a link to the image I'm trying to change in case you can tell anything from it: http://www.generalwebapps.com/images/header_2_selected.gif.

 

Thanks very much to all in advance for any info!

Link to comment
https://forums.phpfreaks.com/topic/195365-gd-newbie-question/
Share on other sites

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.