PHP Classes

File: class.sni.php

Recommend this page to a friend!
  Classes of Armin Borumand  >  Secure Number Image Creator  >  class.sni.php  >  Download  
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
Author: By
Last change: Changes:
Add png and jpeg support
Change colors
Date: 16 years ago
Size: 1,825 bytes
 

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(1, 211111)*1.57;
        return
round($rand);
    }
    function
create($text){
       
$image=imagecreate(100, 25);
       
$bgcolor=imagecolorallocate($image, $r=rand(242,255), rand(247,255), 233);
       
$textcolor=imagecolorallocate($image, 151, 153, 127);
       
$fonth=imagefontheight(5);
       
$fontw=imagefontwidth(5);
       
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<2; $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;
    }
    }
?>