iWidth = 10 + ($iNumChars << 4); $this->iHeight = 21; $this->iNumChars = $iNumChars; for ($i = 0, $zz = 0; $i < strlen($this->sFont) >> 2; $i++) { $r = hexdec($this->sFont[$zz++] . $this->sFont[$zz++]); $c = hexdec($this->sFont[$zz++] . $this->sFont[$zz++]); for ($z = 0; $z < $r; $z++) $this->sCompiledFont .= chr($c); } $this->bBlur = false; $this->bPixels = false; for ($i = 0; $i < $this->iNumChars; $i++) $this->sCode .= rand(0, 9); } function PutNumber($image, $number, $color, $x, $y) { for ($yy = 0; $yy < 16; $yy++) for ($xx = 0; $xx < 14; $xx++) if ($this->sCompiledFont[($number * 14) + $xx + (($yy >> 1) * 140)] == 'x') $this->oImage[$x + $xx + (($y + $yy) * $this->iWidth)] = $color; } function GetPixel($x, $y) { if ($y >= 0 && $y <= $this->iHeight) if ($x >= 0 && $x <= $this->iWidth) return $this->oImage[$x + ($y * $this->iWidth)]; return 63; } function BlurImage($image) { $z = 0; for ($y = 0; $y < $this->iHeight; $y++) { for ($x = 0; $x < $this->iWidth; $x++) { $b = $this->bBlur ? rand(0, 1) : 0; $c = $this->GetPixel($x - $b, $y - 1); $c += $this->GetPixel($x, $y - 1); $c += $this->GetPixel($x + $b, $y - 1); $c += $this->GetPixel($x - $b, $y); $c += $this->GetPixel($x, $y); $c += $this->GetPixel($x + $b, $y); $c += $this->GetPixel($x - $b, $y+$b); $c += $this->GetPixel($x, $y+$b); $c += $this->GetPixel($x + $b, $y+$b); $c /= 9; $this->oImage[$z++] = $c; } } } function Create($sFilename = '') { $image = imagecreate($this->iWidth, $this->iHeight); for ($i = 0; $i < 64; $i++) imagecolorallocate($image, $i << 2, $i << 2, $i << 2); for ($y = 0; $y <= $this->iHeight; $y++) for ($x = 0; $x <= $this->iWidth; $x++) $this->oImage[$x + ($y * $this->iWidth)] = 64; for ($i = 0; $i < strlen($this->sCode); $i++) $this->PutNumber($image, $this->sCode[$i], rand(16, 32), 5 + ($i << 4), 2); if ($this->bPixels) for ($i = 0; $i < 256; $i++) $this->oImage[rand(0, $this->iWidth * $this->iHeight)] = 0; $this->BlurImage($image); for ($z = 0, $y = 0; $y < $this->iHeight; $y++) for($x = 0; $x < $this->iWidth; $x++) imagesetpixel($image, $x, $y, $this->oImage[$z++]); if (empty($sFileName)) { header("Content-type: image/png"); imagepng($image); } else imagepng($image, $sFileName); return true; } function GetCode() { return $this->sCode; } } ?>