//Reads the origonal colors pixel by pixelThe first thing you will see in this code is two loops, one related to the Y value, the other to the X value. These loop through to form the coordinates for each pixel in our photo.
for ($y=0;$y<$height;$y++)
{
for ($x=0;$x<$width;$x++)
{
$rgb = imagecolorat($source,$x,$y);
$r = ($rgb >> 16) & 0xFF;
$g = ($rgb >> 8) & 0xFF;
$b = $rgb & 0xFF;
//This is where we actually use yiq to modify our rbg values, and then convert them to our grayscale palette
$gs = yiq($r,$g,$b);
imagesetpixel($bwimage,$x,$y,$palette[$gs]);
}
}
// Outputs a jpg image, but you can change this to png or gif if that is what you are working with
imagejpeg($bwimage);
?>
We use the function imagecolorat () to get the index color of each pixel, and then apply our yiq () filter. Finally we use imagesetpixel to reset the pixel to the appropriate value on our grayscale palette. Then the loop starts over and we do it to the next pixel, until all the pixels have been reassigned to a grey shade.
Finally we create our black and white image as a JPG.


