= $imagex) { $colours[] = $thiscol; continue; } if ($l < 0) { $colours[] = $thiscol; continue; } if ($l >= $imagey) { $colours[] = $thiscol; continue; } // if not outside the image bounds, get colour at this pixel $colours[] = imagecolorat($image, $k, $l); } } // cycle through all the colours we can use for/ sampling foreach($colours as $colour) { // add their red, green, and blue values to our master //numbers $newr += ($colour >> 16) & 0xFF; $newg += ($colour >> 8) & 0xFF; $newb += $colour & 0xFF; } // now divide the master numbers by the number of valid //samples to get an average $numelements = count($colours); $newr /= $numelements; $newg /= $numelements; $newb /= $numelements; // and use the new numbers as our colour $newcol = imagecolorallocate($image, $newr,$newg, $newb); imagefilledrectangle($image, $x, $y, $x + $blocksize - 1, $y + $blocksize - 1, $newcol); } } } $image = imagecreatefromjpeg("UNICORN.JPG"); pixelate($image); header("Content-type: image/jpeg"); imagejpeg($image); //imagejpeg($image, ('PIXEL2.jpg')); imagedestroy($image); ?>