<?php 
set_time_limit(3600);

header('Content-type: image/jpeg');
$dir = './';
$file = 'test1.jpg';
list($width, $height, $type, $attr) = getimagesize($dir.$file);
$img = imagecreatetruecolor($width, $height);
$img2 = imagecreatefromjpeg($dir.$file);
imagecopy($img , $img2, 0, 0, 0, 0, $width, $height);
for($i = 0; $i < $width; $i++){
	for($j = 0; $j < $height; $j++){
		$rgb = imagecolorat($img, $i, $j);
		$r = ($rgb >> 16) & 0xFF;
		$g = ($rgb >> 8) & 0xFF;
		$b = $rgb & 0xFF;

		if($r < 20 && $g < 20 && $b < 20){
			imagefilledrectangle($img, $i, $j, $i, $j, imagecolorallocate($img, 20, 20, 20));
		}
		
		
		
		unset($r);
		unset($g);
		unset($b);
		unset($rgb);
	}
}

imagejpeg($img);
exit;
?>