All pastes #544315 Raw Edit

Someone

public php v1 · immutable
·published 2007-06-06 11:57 UTC
rendered paste body
<?php//error_reporting(E_ALL);session_start();if(!$_GET["typed"]){	$captcha = imagecreatefrompng("profile.png");	$height = imagesy($captcha);	$width = imagesx($captcha);	$threshold = 128;	for($x=0;$x<$width;$x++)	{		for($y=0;$y<$height;$y++)		{				$pixelValue =  imagecolorat($captcha,$x,$y);			if($pixelValue > $threshold)			{				imagesetpixel($captcha,$x,$y,255);			}			else			{				imagesetpixel($captcha,$x,$y,0);				$blackPixels[] = array($x,$y);			}		}	}	foreach($blackPixels as $blackPixel)	{		imagesetpixel($captcha,$blackPixel[0]+1,$blackPixel[1]+1,0);		imagesetpixel($captcha,$blackPixel[0],$blackPixel[1]+1,0);		imagesetpixel($captcha,$blackPixel[0],$blackPixel[1]-1,0);		imagesetpixel($captcha,$blackPixel[0]+1,$blackPixel[1],0);		imagesetpixel($captcha,$blackPixel[0]-1,$blackPixel[1],0);		imagesetpixel($captcha,$blackPixel[0]+1,$blackPixel[1]-1,0);		imagesetpixel($captcha,$blackPixel[0]-1,$blackPixel[1]+1,0);		imagesetpixel($captcha,$blackPixel[0]-1,$blackPixel[1]+1,0);	}	$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) == 0)			{				$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;			$croppedLetter = imagecreate($newWidth,$newHeight);			imagecopy($croppedLetter,$captcha,0,0,$data["x1"],$highestY,$width,$newHeight);			$captchas[] = $croppedLetter;			imagepng($croppedLetter,"tmp-$count.png");			//imagerectangle($captcha,$data["x1"],$lowestY,$data["x2"],$highestY,"#FFFFFF");			$startedCharacter = False;			$highestY = 10000;			$lowestY = 0;			$count++;		}	}	$count = 0;	$_SESSION["captchaCount"] = count($captchas);	echo "	<form action=" . $_SERVER["PHP_SELF"] . " method=GET>\n";	for($c=0;$c<count($captchas);$c++)	{		echo "<img src=tmp-$c.png>\n";	}	echo "<input type=text name=captcha>\n<input type=hidden name=typed value=\"true\">\n<input type=submit value=submit>\n</form>";}else{	$arrayLetters = preg_split("//",$_GET["captcha"],-1,PREG_SPLIT_NO_EMPTY);	for($c=0 ; $c<	$_SESSION["captchaCount"] ;$c++)	{		@copy("tmp-$c.png","phpbb-captcha/" . $arrayLetters[$c] . ".png");	}	echo "<a href=" . $_SERVER["PHP_SELF"] . ">Again</a>";}?>