linea21-core
[ class tree: linea21-core ] [ index: linea21-core ] [ all elements ]

Source for file class.codimage.php

Documentation is available at class.codimage.php

  1. <?php
  2. /**
  3.  * @package linea21.core
  4.  * @subpackage system
  5.  * @author linea21 <info@linea21.com>
  6.  * @version $id SVN
  7.  * @access public
  8.  * @license http://opensource.org/licenses/gpl-3.0.html
  9.  *  Generate code-image
  10.  */
  11.  
  12. class codimage {
  13.   /* @parameters
  14.    * */
  15.   var $CURRENT_IMG;
  16.   var $IMG_SRC="../templates/admin/default/images/security_fili.png";
  17.   var $FONT_SIZE=16// taille de la police
  18.   var $FONT="../class/system/artichow/font/Vera.ttf"// repertoire Police
  19.   var $ANGLE=0;
  20.   var $PADDING_X=10;
  21.   var $PADDING_Y=10;
  22.   var $TEXT_LENGTH=5;
  23.   var $TEXT=5;
  24.   var $FONT_COLOR;
  25.  
  26.   function codimage({
  27.     $this->GetRandomText();
  28.     $size imagettfbbox($this->FONT_SIZE,$this->ANGLE,$this->FONT,$this->TEXT);
  29.     $dx abs($size[2]-$size[0]);
  30.     $dy abs($size[5]-$size[3]);
  31.     $this->CURRENT_IMG = imagecreate($dx+$this->PADDING_X,$dy+$this->PADDING_Y);
  32.     $picsrc imagecreatefrompng($this->IMG_SRC);
  33.     Imagecopymerge $this->CURRENT_IMG  ,  $picsrc 0  0  0  0  imagesx($this->CURRENT_IMG)  imagesy($this->CURRENT_IMG),100);
  34.     $this->GetFontColor();
  35.     ImageTTFText($this->CURRENT_IMG$this->FONT_SIZE$this->ANGLE(int)($this->PADDING_X/2)+1$dy+(int)($this->PADDING_Y/2)$this->FONT_COLOR$this->FONT$this->TEXT);
  36.   }
  37.  
  38.   function Output({
  39.     Header("Content-type: image/png");
  40.     ImagePng($this->CURRENT_IMG);
  41.     ImageDestroy($this->CURRENT_IMG);
  42.   }
  43.  
  44.   function GetBackgroundColor({
  45.     if(empty($this->BACKGROUND_COLOR))    $this->SetBackgroundColor();
  46.     return true;
  47.   }
  48.  
  49.   function SetBackgroundColor($r=200$v=200$b=200{
  50.     $this->BACKGROUND_COLORImageColorAllocate($this->CURRENT_IMG$r$v$b);
  51.     return true;
  52.   }
  53.  
  54.   function GetRandomText()
  55.   {
  56.     $str 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
  57.     $text '';
  58.     for ($i 0$i $this->TEXT_LENGTH$i++{
  59.       $text .= substr($strrand(0strlen($str1)1);
  60.     }
  61.     $this->TEXT=$text;
  62.   }
  63.  
  64.   function SetFontSize($size)
  65.   {
  66.     $this->FONT_SIZE=$size;
  67.     return true;
  68.   }
  69.  
  70.   function SetPaddingX($pad)
  71.   {
  72.     $this->PADDING_X=$pad;
  73.     return true;
  74.   }
  75.  
  76.   function SetPaddingY($pad)
  77.   {
  78.     $this->PADDING_Y=$pad;
  79.     return true;
  80.   }
  81.  
  82.   function GetFontColor({
  83.     if(empty($this->FONT_COLOR))    $this->SetFontColor();
  84.     return true;
  85.   }
  86.  
  87.   function SetFontColor($r=0$v=0$b=0)
  88.   {
  89.     $this->FONT_COLORImageColorAllocate($this->CURRENT_IMG$r,$v$b);
  90.     return true;
  91.   }
  92.  
  93. }
  94.  
  95. ?>

Documentation generated on Thu, 03 May 2012 15:02:18 +0200 by phpDocumentor 1.4.1