Login   Register  
PHP Classes
elePHPant
Icontem

File: class.sni.php

Recommend this page to a friend!
Stumble It! Stumble It! Bookmark in del.icio.us Bookmark in del.icio.us
  Classes of Armin Borumand  >  Secure Number Image Creator  >  class.sni.php  
File: class.sni.php
Role: Class source
Content type: text/plain
Description: sni class
Class: Secure Number Image Creator
Generate an image with a random number or text
 

Contents

Class file image Download
<?php
/*********************************
Secure Number Image creator
Author        : Armin Borumand
E-mail        : armin390@gamil.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(1211111)*1.57;
        return 
round($rand);
    }
    function 
create($text){
        
$image=imagecreate(10025);
        
$bgcolor=imagecolorallocate($image$r=rand(242,255), rand(247,255), 233);
        
$textcolor=imagecolorallocate($image151153127);
        
$fonth=imagefontheight(5);
        
$fontw=imagefontwidth(5);
        
imagestring($image5$x=rand(045), $y=rand(025-$fonth), $text$textcolor);
        
imageline($image$xrand($y,$y+$fonth), $x+$fontw*6rand($y,$y+$fonth), $textcolor);
        
imageline($image$xrand($y,$y+$fonth), $x+$fontw*6rand($y,$y+$fonth), $bgcolor);
        for(
$i=0$i<2$i++)
            
$this->imageset9pixel($imagerand($x$x+$fontw*6), rand($y$y+$fonth), $bgcolor);
        for(
$i=0$i<10$i++)
            
$this->imageset9pixel($imagerand(0100), 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;
    }
    }
?>