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:  * Application d'effet sur une image
 17:  * 
 18:  * @category Pry
 19:  * @package Image
 20:  * @version 1.0.0 
 21:  * @author Olivier ROGER <oroger.fr>
 22:  */
 23: class Traitement
 24: {
 25: 
 26:     /**
 27:      * Objet représentant l'image
 28:      *
 29:      * @var Image
 30:      */
 31:     private $objet;
 32: 
 33:     /**
 34:      * Ressource de l'image à modifier
 35:      *
 36:      * @var ressource
 37:      */
 38:     private $sourceImage;
 39: 
 40:     /**
 41:      * Dimension X de l'image
 42:      *
 43:      * @var int
 44:      */
 45:     private $largeur;
 46: 
 47:     /**
 48:      * Dimension Y de l'image
 49:      *
 50:      * @var int
 51:      */
 52:     private $hauteur;
 53: 
 54:     /**
 55:      * Constructeur
 56:      * 
 57:      * @param Image $img Objet de l'image
 58:      */
 59:     public function __construct(Image &$img)
 60:     {
 61:         if (!is_object($img))
 62:         {
 63:             throw new Exception('Objet attendu');
 64:         }
 65: 
 66:         $this->objet       = $img;
 67:         $this->sourceImage = $this->objet->getSource();
 68:         $data              = $this->objet->getInfo();
 69:         $this->largeur     = $data['width'];
 70:         $this->hauteur     = $data['height'];
 71:     }
 72: 
 73:     /**
 74:      * Convertit l'image en niveau de gris. Imagefilter remplace les calcul via matrice. 10x plus rapide
 75:      * @access public
 76:      */
 77:     public function greyScale()
 78:     {
 79:         if (imagefilter($this->sourceImage, IMG_FILTER_GRAYSCALE))
 80:             $this->objet->setSource($this->sourceImage);
 81:     }
 82: 
 83:     /**
 84:      * Ajoute du flou à l'image. Imagefilter remplace les calcul via matrice. 10x plus rapide
 85:      * @access public
 86:      * @param int $factor Facteur de flou
 87:      */
 88:     public function blur($factor)
 89:     {
 90:         if (imagefilter($this->sourceImage, IMG_FILTER_GAUSSIAN_BLUR, $factor))
 91:             $this->objet->setSource($this->sourceImage);
 92:     }
 93: 
 94:     /**
 95:      * Ajoute du bruit à l'image. (relativement long a executer puisque traitement px par px)
 96:      * @access public
 97:      * @param int $factor paramètre de bruit (0-255)
 98:      * 
 99:      */
100:     public function addNoise($factor)
101:     {
102:         for ($x = 0; $x < $this->largeur; $x++) {
103:             for ($y = 0; $y < $this->hauteur; $y++) {
104:                 $rand = mt_rand(-$factor, $factor);
105:                 $rgb  = imagecolorat($this->sourceImage, $x, $y);
106:                 $r    = (($rgb >> 16) & 0xFF) + $rand;
107:                 $g    = (($rgb >> 8) & 0xFF) + $rand;
108:                 $b    = ($rgb & 0xFF) + $rand;
109: 
110:                 $color = imagecolorallocate($this->sourceImage, $r, $g, $b);
111:                 imagesetpixel($this->sourceImage, $x, $y, $color);
112:             }
113:         }
114:         $this->objet->setSource($this->sourceImage);
115:     }
116: 
117:     /**
118:      * Netteté
119:      * @access public
120:      */
121:     public function sharppen()
122:     {
123:         if (imagefilter($this->sourceImage, IMG_FILTER_MEAN_REMOVAL))
124:             $this->objet->setSource($this->sourceImage);
125:     }
126: 
127:     /**
128:      * Modifie le contraste de l'image. Imagefilter remplace les calcul via matrice. 10x plus rapide
129:      * @access public
130:      * @param int $factor Facteur de flou
131:      */
132:     public function contrast($factor)
133:     {
134:         if (imagefilter($this->sourceImage, IMG_FILTER_CONTRAST, $factor))
135:             $this->objet->setSource($this->sourceImage);
136:     }
137: 
138:     /**
139:      * Modifie la luminosité. Imagefilter remplace les calcul via matrice. 10x plus rapide
140:      * @access private
141:      * @param int $factor Facteur de flou
142:      */
143:     public function brightness($factor)
144:     {
145:         if (imagefilter($this->sourceImage, IMG_FILTER_BRIGHTNESS, $factor))
146:             $this->objet->setSource($this->sourceImage);
147:     }
148: 
149: }
150: 
151: ?>
Pry API documentation generated by ApiGen 2.8.0