Location: PHPKode > projects > iPei Guestbook > ipei-guestbook/guestbook/snic.php
<?php
/*********************************
Secure Number Image creator
Author        : Armin Borumand
E-mail        : hide@address.com
*********************************/
class sni{
	var $show;
	var $imp;
	function sni($text=""){
		$this->show=$text==""?$this->random():$text;
		$this->imp=$this->create($this->show);
		$this->show($this->imp,"jpeg");
	}
	function random(){
		$rand = rand(1, 211111)*1.66;
		return round($rand);
	}
	function create($text){
		$image=imagecreate(100, 25);
		$bgcolor=imagecolorallocate($image, $r=rand(249,254), rand(243,253), 253);
		$textcolor=imagecolorallocate($image, 51, 53, 27);
		$fonth=imagefontheight(6);
		$fontw=imagefontwidth(6);
		imagestring($image, 5, $x=rand(0, 45), $y=rand(0, 25-$fonth), $text, $textcolor);
		imageline($image, $x, rand($y,$y+$fonth), $x+$fontw*6, rand($y,$y+$fonth), $textcolor);
		//imageline($image, $x, rand($y,$y+$fonth), $x+$fontw*6, rand($y,$y+$fonth), $bgcolor);
		for($i=0; $i<5; $i++)
			$this->imageset9pixel($image, rand($x, $x+$fontw*6), rand($y, $y+$fonth), $bgcolor);
		for($i=0; $i<10; $i++)
			$this->imageset9pixel($image, rand(0, 100), rand(0,25), $textcolor);
		return $image;
		
	}
	function imageset9pixel($image,$x,$y,$color){
		for($i=$x-1;$i<$x+1;$i++){
			for($j=$y-1;$j<$y+1;$j++)
				imagesetpixel($image,$i,$j,$color);
		}
	}
	function show($image, $type="gif"){
		switch($type){
			case "gif":
			header("Content-type: image/".$type);
			imagegif($image);
			break;						
			case "jpeg":
			header("Content-type: image/".$type);
			imagejpeg($image);
			break;
			case "png":
			header("Content-type: image/".$type);
			imagepng($image);
			break;
			default:
			die("Type error");
		}
		imagedestroy($image);
	}
	function getnum(){
		return $this->show;
	}
	}
?>
Return current item: iPei Guestbook