This function will convert JPEG image to monochrome, reduce the filesize 90%, and increase the readability. All good things. Please implement this.
Note: This requires that you have PHP GD installed for Image manipulation.
function convertJPEGtoMonochromeGIF( $infile, $outfile ) {
list($width, $height) = getimagesize($infile);
$source = imagecreatefromjpeg($infile);
$bwimage= imagecreate($width, $height);
$paletteBlack = imagecolorallocate( $bwimage, 0, 0, 0 );
$paletteWhite = imagecolorallocate( $bwimage, 255, 255, 255 );
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;
$gs = (($r*0.299)+($g*0.587)+($b*0.114));
if ( $gs > 150 )
imagesetpixel($bwimage,$x,$y,$paletteWhite);
else
imagesetpixel($bwimage,$x,$y,$paletteBlack);
}
imagegif( $bwimage, $outfile );
}