All pastes #570661 Raw Edit

Miscellany

public text v1 · immutable
·published 2007-06-16 20:26 UTC
rendered paste body
$startedCharacter = False;
	$highestY = 10000;
	$lowestY = 0;
	$count = 0;
	for($x=0;$x<$width;$x++)
	{
		$hasBlack = False;
		for($y=0;$y<$height;$y++)
		{
			if(imagecolorat($captcha,$x,$y) == 255)
			{
				$hasBlack = True;
				if($y<$highestY){
					$highestY = $y;
				}
				if($y>$lowestY){
					$lowestY = $y;
				}
				$eax = $y;
				if(!$startedCharacter)
				{
				
					$data["x1"] = $x;
					$data["y1"] = $y;
					$startedCharacter = True;
				}
			}
			
		}
		
		if(($startedCharacter) && (!$hasBlack))
		{
			$data["x2"] = $x;
			$data["y2"] = $eax;
			$newWidth = $data["x2"] - $data["x1"];
			$newHeight = $lowestY - $highestY;
			if($newWidth > 2 && $newHeight > 2){
			$croppedLetter = imagecreate($newWidth,$newHeight);
			imagecopy($croppedLetter,$captcha,0,0,$data["x1"],$highestY,$newWidth,$newHeight);
			$captchas[] = $croppedLetter;
			imagepng($croppedLetter,"tmp-$count.png");
			$startedCharacter = False;
			$highestY = 10000;
			$lowestY = 0;
			$count++;
			}
		}

	}