Overview

Packages

  • Auth
  • Config
  • Controller
  • Date
  • Db
  • Feed
    • Abstract
    • Writers
  • File
    • Decorator
  • Form
    • Element
  • Image
  • Log
    • Writer
  • Net
    • Exception
  • None
  • PHP
  • PHPMailer
  • Session
  • Util
  • Validate
    • Validator
  • Zend
    • Registry

Classes

  • Image_Captcha
  • Image_Converter
  • Image_DegradeCouleur
  • Image_Font
  • Image_Gauge
  • Image_Image
  • Image_Traitement

Exceptions

  • Image_Exception
  • Overview
  • Package
  • Class
  • Tree
  1: <?php
  2: /**
  3:  * Pry Framework
  4:  *
  5:  * LICENSE
  6:  *
  7:  * This source file is subject to the new BSD license that is bundled
  8:  * with this package in the file LICENSE.txt.
  9:  * 
 10:  * @version $Revision: 276 $
 11:  */
 12: 
 13: define('RESOURCEFOLDER',dirname(__FILE__).DIRECTORY_SEPARATOR.'resource');
 14: /**
 15:  * Dessine une jauge type jauge à essence.
 16:  * Inspiré de Stephen Powis PHPDialGauge
 17:  * <code>
 18:  * $gauge = new Image_gauge(50);
 19:  * $gauge->draw();
 20:  * $gauge->display();
 21:  * </code>
 22:  * @category Pry
 23:  * @package Image
 24:  * @version 1.1.0 
 25:  * @author Olivier ROGER <oroger.fr>
 26:  */
 27: class Image_Gauge extends Image_Image 
 28: {
 29:     
 30:     private $gauge_needle;
 31:     private $gauge;
 32:     private $blank;
 33:     private $value;
 34:     private $max;
 35:     private $min;
 36:     
 37:     /**
 38:      * Constructeur. Définition des images de base
 39:      *
 40:      * @param int $value Valeur à afficher
 41:      * @param int $min Valeur minimale
 42:      * @param int $max Valeur maximale
 43:      */
 44:     public function __construct($value,$min=0,$max=100)
 45:     {
 46:         $this->value        = $value;
 47:         $this->max          = $max;
 48:         $this->min          = $min;
 49:         $this->gauge_needle = RESOURCEFOLDER.DIRECTORY_SEPARATOR.'gauge_needle.png';
 50:         $this->gauge        = RESOURCEFOLDER.DIRECTORY_SEPARATOR.'gauge_blank.png';
 51:         $this->blank        = RESOURCEFOLDER.DIRECTORY_SEPARATOR.'blank.png';
 52:     }
 53:     
 54:     /**
 55:      * Défini une image de jauge
 56:      *
 57:      * @param string $jauge chemin vers l image
 58:      * @access public
 59:      */
 60:     public function setGauge($jauge)
 61:     {
 62:         if(file_exists($jauge))
 63:             $this->gauge = $jauge;
 64:         else
 65:             throw new Image_Exception('Le fichier '.$jauge.' image n\'existe pas');
 66:     }
 67:     
 68:     /**
 69:      * Défini l image de l'aiguille
 70:      *
 71:      * @param string $aiguille Chemin vers l'image de l'aiguille
 72:      * @access public
 73:      */
 74:     public function setNeedle($aiguille)
 75:     {
 76:         if(file_exists($aiguille))
 77:             $this->gauge_needle = $aiguille;
 78:         else
 79:             throw new Image_Exception('Le fichier '.$aiguille.' image n\'existe pas');
 80:     }
 81:     
 82:     /**
 83:      * Dessine la jauge
 84:      * @access public
 85:      */
 86:     public function draw()
 87:     {
 88:         parent::__construct($this->gauge);
 89:         $this->setType(parent::IMG_PNG);
 90:         
 91:         $this->setFont('arial');
 92:         $this->setColor(231,34,34);
 93:         $this->setText($this->min,8,44,117);
 94:         $this->setColor(23,140,4);
 95:         $this->getValueColor();
 96:         $this->setText($this->max,8,105,117);
 97:         $this->setText($this->value.'%',14,$this->computeXposValue(),145);
 98:         
 99:         $angle          = $this->computeAngle();
100:         $needle         = new Image_Image($this->gauge_needle);
101:         $tailleNeedle   = $needle->getInfo();
102:         $needle->rotate(-$angle);
103:         
104:         $fond   = $this->getSource();
105: 
106:         $aiguille = $needle->getSource();
107:         $tailleNewNeedleX = imagesx($aiguille);
108:         $tailleNewNeedleY = imagesy($aiguille);
109:         
110:         
111:         $gauge = imagecreatefrompng($this->blank);
112:         imageAlphaBlending($gauge, true);
113:         imageSaveAlpha($gauge, true);
114:         //Crop de l aiguille
115:         imagecopy($gauge,$aiguille,0,0,round(($tailleNewNeedleX-$tailleNeedle['width'])/2)+33,round(($tailleNewNeedleY-$tailleNeedle['height'])/2)+33,$tailleNeedle['width'],$tailleNeedle['height']);
116:         //position au centre
117:         imagecopy($fond,$gauge,0,0,0,0,165,165);
118:         $this->setSource($fond);
119:         
120:         /*if(is_resource($fond))
121:             imagedestroy($fond);
122:         if(is_resource($gauge))
123:             imagedestroy($gauge);
124:         if(is_resource($aiguille))
125:             imagedestroy($aiguille);*/
126:     }
127:     
128:     /**
129:      * Calcul l'angle de rotation
130:      *
131:      * @return int
132:      * @access private
133:      */
134:     private function computeAngle()
135:     {
136:         return (($this->value - $this->min)*260)/($this->max - $this->min);
137:     }
138:     
139:     /**
140:      * Attribue une couleur au texte de la valeur
141:      * @access private;
142:      *
143:      */
144:     private function getValueColor()
145:     {
146:         if($this->value<30)
147:             $this->setColor(231,34,34); // ROUGE
148:         elseif($this->value>70)
149:             $this->setColor(23,140,4); //VERT
150:         else
151:             $this->setColor(237,237,9); //Jaune
152:     }
153:     
154:     /**
155:      * Défini une postion pour le texte de la valeur en fonction de sa taille
156:      *
157:      * @return int
158:      * @access private
159:      */
160:     private function computeXposValue()
161:     {
162:         $taille = strlen($this->value);
163:         switch($taille)
164:         {
165:             case 1:
166:                 $pos = 70;
167:                 break;
168:             case 2:
169:                 $pos = 70;
170:                 break;
171:             case 3:
172:                 $pos = 60;
173:                 break;
174:             default :
175:                 $pos = 70;
176:                 break;
177:         }
178:         return $pos;
179:     }
180: }
181:  ?>
Pry Framework API documentation generated by ApiGen 2.6.1