site logo image  |   home   |   advanced scripts   |   custom script   |   forum   |   contact us   |   links  | 
 



 function name: random_image
 
 language:  PHP5
 platforms:  Linux,Windows
 
 description:   generate random image
 
    

<?php
/**
*   requires: PHP5
*   author: Konstantin Atanasov
*
*
*/


  
class   random_image  {
  
      
private $text
      
private $text_color;
      
private $background_color;
      
private $font_size;
      
private $random_x;
      
private $random_y;
      
private $image;
      
private $width;
      
private $height;
      
private $char_space;
      
      
// border
      
private $border_color;
      
private $border_size;
            
      
/**
      *     constructor
      *
      */
      
public function __construct($image_text)  {
            
$this->text $image_text;
            
$this->init();
            
$this->draw();
      }
      
      
/**
      *
      *   init image properties
      */
      
private function init() {
      
        
$this->random_x 18;
        
$this->random_y 18;
        
$this->width = (strlen($this->text) * 30);
        
$this->height 50;
        
        
$this->char_space $this->width / ( strlen($this->text) + 1);
        
// text color
        
$this->color_r 0;
        
$this->color_g 0;
        
$this->color_b 0;
        
// background color
        
$this->background_r 255;
        
$this->background_g 255;
        
$this->background_b 255;
        
// border color
        
$this->border_color_r 100;
        
$this->border_color_g 100;
        
$this->border_color_b 100;
        
      }
      
      
/**
      *
      *   draw image 
      */
      
public function draw() {
      
          
// draw image
          
$this->image imagecreatetruecolor($this->width,$this->height);
          
$this->text_color imagecolorallocate($this->image,$this->color_r,$this->color_g,$this->color_b);
          
$this->background_color imagecolorallocate($this->image,$this->background_r,$this->background_g,$this->background_b);
          
$this->border_color imagecolorallocate($this->image,$this->border_color_r,$this->border_color_g,$this->border_color_b);
        
          
          
//imagefilledrectangle($this->image,0,0,$this->widht,$this->height,$this->background_color);
          
imagefill($this->image,0,0,$this->background_color);
          
imagerectangle($this->image,0,0,$this->width-1,$this->height-1,$this->border_color);
          
          
// draw text
          
for ($pos 0$pos strlen($this->text);$pos++) {
              
imagettftext($this->image,25 rand(0,5),-10 rand(0,30),
                          (
$pos 0.5) * $this->char_space,35 rand(0,15),
                          
$this->text_color,'arial.ttf',$this->text{$pos});
                              
              
imageline($this->image,($pos ) * $this->char_space ,0,($pos 1) * $this->char_space,30 rand(0,10),$this->text_color);
          }
          
          
      }
      
      
/**
      *
      *   return image to browser
      */
      
public function get_image() {
          
header("Content: image/jpg");
          
imagejpeg($this->image);
      }
      
      
/**
      *
      *     set image text
      */
      
public function set_text($text) {
        
$this->text $text;
      }
      
  } 
// end class
  
  
  
  
  // create default object
  
$random_image = new random_image("234514");
  
$random_image->get_image();
  
?>

 
 

2checkout

hotscripts.com


     
     
  © 2005 - 2007 www.SourceWorkshop.com    All right reserved.