1: <?php
2:
3: 4: 5: 6: 7: 8: 9: 10: 11:
12:
13: namespace Pry\Image;
14:
15: 16: 17: 18: 19: 20: 21: 22:
23: class Traitement
24: {
25:
26: 27: 28: 29: 30:
31: private $objet;
32:
33: 34: 35: 36: 37:
38: private $sourceImage;
39:
40: 41: 42: 43: 44:
45: private $largeur;
46:
47: 48: 49: 50: 51:
52: private $hauteur;
53:
54: 55: 56: 57: 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: 75: 76:
77: public function greyScale()
78: {
79: if (imagefilter($this->sourceImage, IMG_FILTER_GRAYSCALE))
80: $this->objet->setSource($this->sourceImage);
81: }
82:
83: 84: 85: 86: 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: 96: 97: 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: 119: 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: 129: 130: 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: 140: 141: 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: ?>