Grayscaling


<?php

$rd=imagecreatefromjpeg('testing.jpg');
$W=imagesx($rd);
$H=imagesy($rd);
for ($x=0; $x<$W; $x++){
   for ($y=0; $y<$H; $y++){
      $rgb = imagecolorat($rd, $x, $y);
      $r = ($rgb >> 16) & 0xFF;
      $g = ($rgb >> 8) & 0xFF;
      $b = $rgb & 0xFF;
      $Ave = ($r+$g+$b)/3;
      imagesetpixel($rd, $x, $y, 
                          imagecolorallocate($rd, $Ave, $Ave, $Ave));
   }
}
imagejpeg($rd,'testing11.jpg');

?>