title: How can I replace one color with another in a png 24 alpha transparent image with GD
body: <p>I have tried:</p>
  
  <pre><code>$index = imagecolorresolve ( $im,  0,0,0 ); // get black
  imagecolorset($im, $index, 255, 0, 255); // SET NEW COLOR
  </code></pre>
  
  <p>This seems to work with png 8 but not 24, and if I do it with 8 it turns out all weird because of the anti-aliasing. </p>
  
  <p>Here is the full test code I'm using. (this is just test code, so be gentle).</p>
  
  <pre><code>function LoadPNG($imgname, $color = false)
  {        
      $im = @imagecreatefrompng($imgname);
      imagealphablending($im, false); 
  
      if($color) {
        $index = imagecolorresolve ( $im,  0,0,0 ); // get black
        imagecolorset($im, $index, 255, 0, 255); // SET NEW COLOR
      }
  
      imageAlphaBlending($im, true);
      imageSaveAlpha($im, true);
  
      return $im;
  }
  
  header('Content-Type: image/png');
  
  $img = LoadPNG("head.png", "red");
  
  imagepng($img);
  imagedestroy($img);
  </code></pre>