Overview

Namespaces

  • None
  • PHP
  • Pry
    • Auth
      • Interfaces
    • Config
    • Controller
    • Date
    • Db
    • Feed
      • Abstracts
      • Writers
    • File
      • Decorator
    • Form
      • Element
    • Image
    • Log
      • Writer
    • Net
      • Exception
    • Session
    • Util
    • Validate
      • Validator
    • View

Classes

  • Captcha
  • Converter
  • DegradeCouleur
  • Font
  • Gauge
  • Image
  • Traitement

Exceptions

  • Exception
  • Overview
  • Namespace
  • Class
  • Tree
  1: <?php
  2: 
  3: /**
  4:  * Pry Framework
  5:  *
  6:  * LICENSE
  7:  *
  8:  * This source file is subject to the new BSD license that is bundled
  9:  * with this package in the file LICENSE.txt.
 10:  * 
 11:  */
 12: 
 13: namespace Pry\Image;
 14: 
 15: /**
 16:  * Créer un dégradé de couleur à partir d'une couleur de début et une de fin.
 17:  * 
 18:  * <code>
 19:  * $image = new DegradeCouleur(110,110);
 20:  * $image->startColor = $image->hexToRgb('28abe2');
 21:  * $image->endColor   = $image->hexToRgb('2d3192');
 22:  * print_r($image->startColor);
 23:  * $image->direction  = DegradeCouleur::DEGRADE_HORIZONTAL;
 24:  * $image->degrade();
 25:  * $image->setType(DegradeCouleur::IMG_JPG);
 26:  * $image->save('test.jpg');      
 27:  * </code>
 28:  * 
 29:  * @category Pry
 30:  * @package Image
 31:  * @version 1.2.0 
 32:  * @author Olivier ROGER <oroger.fr>
 33:  * 
 34:  */
 35: class DegradeCouleur extends Image
 36: {
 37: 
 38:     const DEGRADE_HORIZONTAL = 0;
 39:     const DEGRADE_VERTICAL   = 1;
 40:     const DEGRADE_DIAGONAL   = 2;
 41: 
 42:     /**
 43:      * Direction du dégradé
 44:      * @access public
 45:      * @var int
 46:      */
 47:     public $direction;
 48: 
 49:     /**
 50:      * Couleur de début
 51:      * @access public
 52:      * @var array
 53:      */
 54:     public $startColor;
 55: 
 56:     /**
 57:      * Couleur de fin
 58:      * @access public
 59:      * @var array
 60:      */
 61:     public $endColor;
 62: 
 63:     /**
 64:      * Largeur de l'image
 65:      * @access private
 66:      * @var int
 67:      */
 68:     private $largeur;
 69: 
 70:     /**
 71:      * Hauteur de l'image
 72:      * @access private
 73:      * @var int
 74:      */
 75:     private $hauteur;
 76: 
 77:     /**
 78:      * Constructeur
 79:      *
 80:      * @param int $width
 81:      * @param int $height
 82:      */
 83:     public function __construct($width, $height)
 84:     {
 85:         parent::__construct(null, $width, $height);
 86:         $this->largeur = $width;
 87:         $this->hauteur = $height;
 88:         if ($width <= 0 || $height <= 0)
 89:             throw new \RangeException('Une image doit avoir des dimension valides');
 90:     }
 91: 
 92:     /**
 93:      * Lance la construction du dégradé
 94:      *
 95:      */
 96:     public function degrade()
 97:     {
 98:         $this->setColor(255, 255, 255);
 99: 
100:         // On défini le nombre de lignes à tracer en fonction du type de dégradé
101:         if ($this->direction == self::DEGRADE_HORIZONTAL)
102:         {
103:             $nbLine = $this->largeur;
104:         }
105:         elseif ($this->direction == self::DEGRADE_VERTICAL)
106:         {
107:             $nbLine = $this->hauteur;
108:         }
109:         else
110:         {
111:             $nbLine = $this->largeur + $this->hauteur;
112:         }
113: 
114:         for ($i = 0; $i < $nbLine; $i++) {
115:             //Calcul de chaque composante en fonction du pas défini par : 
116:             // Ligne*(Composante de fin - Composante de début )/ Nombre de ligne
117:             $red   = $this->startColor[0] + $i * ($this->endColor[0] - $this->startColor[0]) / $nbLine;
118:             $green = $this->startColor[1] + $i * ($this->endColor[1] - $this->startColor[1]) / $nbLine;
119:             $blue  = $this->startColor[2] + $i * ($this->endColor[2] - $this->startColor[2]) / $nbLine;
120: 
121:             //Attribution de la nouvelle couleur
122:             $this->setColor($red, $green, $blue);
123: 
124:             //Dessin de la ligne
125:             if ($this->direction == self::DEGRADE_HORIZONTAL)
126:             {
127:                 //Dégradé Horizontal => dessin de ligne vertical
128:                 imageline($this->source, $i, 0, $i, $this->hauteur, $this->couleur);
129:             }
130:             elseif ($this->direction == self::DEGRADE_VERTICAL)
131:             {
132:                 imageline($this->source, 0, $i, $this->largeur, $i, $this->couleur);
133:             }
134:             else
135:             {
136:                 imageline($this->source, max(0, ($i - $this->hauteur)), min($i, $this->hauteur), min($i, $this->largeur), max(0, ($i - $this->largeur)), $this->couleur);
137:             }
138:         }
139:     }
140: 
141: }
142: 
143: ?>
Pry API documentation generated by ApiGen 2.8.0