I did up this little bit of code. It reads in an image and converts it to grayscale but preserves everything within the specified tolerance of the specified color. Tolerance works by creating a color orb with $tolerance radius so sometimes it preserves unexpected colors. If anyone knows how to fix this let me know.
<?php
$image_dir = 'images/';
$_GET['filename'] = 'stellar2.jpg';
if(!array_key_exists('filename',$_GET)) {die('no file specified');}
elseif(!is_dir($image_dir)) {die('directory not found');}
elseif(!file_exists($image_dir . $_GET['filename'])) {die('file not found');}
elseif(!is_readable($image_dir . $_GET['filename'])) {die('file not readable');}
$filename = $image_dir . $_GET['filename'];
$preserve_color = array(68,80,44); //red, green, blue
$tolerance = 25; //if no color code is off by more then this it will be preserved
list($width,$height,$type,$text) = getimagesize($filename);
//we're only going to do jpeg & png types
switch($type) {
case 2:
$orig_im = imagecreatefromjpeg($filename);
break;
case 3:
$orig_im = imagecreatefrompng($filename);
break;
default:
die();
} //end switch
//go down the picture
for($y=0;$y<$height;$y++) {
//go across the picture
for($x=0;$x<$width;$x++) {
//get the rgb values
$rgb = imagecolorat($orig_im,$x,$y);
$red = ($rgb >> 16) & 0xFF;
$green = ($rgb >> 8) & 0xFF;
$blue = $rgb & 0xFF;
//if we have to convert this pixel
if(abs($red - $preserve_color[0]) > $tolerance &&
abs($green - $preserve_color[1]) > $tolerance &&
abs($blue - $preserve_color[2]) > $tolerance) {
//create the gray value
$gray = round(.299*$red + .598*$green + .114*$blue);
$grayR = $gray << 16;
$grayG = $gray << 8;
$grayB = $gray;
$grayColor = $grayR | $grayG | $grayB;
//reset the pixel color
imagesetpixel($orig_im,$x,$y,$grayColor);
imagecolorallocate($orig_im,$gray,$gray,$gray);
} //end if
} //end for
} //end for
$new_im = imagecreate($width,$height);
//copy the new image included here for convience in making this
//save the file to the disk
imagecopy($new_im,$orig_im,0,0,0,0,$width,$height);
//send the new image to the browser
header('Content-type: image/png');
imagepng($new_im);
imagedestroy($new_im);
imagedestroy($orig_im);
?>