@@ -66,54 +66,54 @@ discard block |
||
66 | 66 | |
67 | 67 | const ERROR_GD_LIBRARY_NOT_INSTALLED = 513024; |
68 | 68 | |
69 | - /** |
|
70 | - * @var string |
|
71 | - */ |
|
69 | + /** |
|
70 | + * @var string |
|
71 | + */ |
|
72 | 72 | protected $file; |
73 | 73 | |
74 | - /** |
|
75 | - * @var ImageHelper_Size |
|
76 | - */ |
|
74 | + /** |
|
75 | + * @var ImageHelper_Size |
|
76 | + */ |
|
77 | 77 | protected $info; |
78 | 78 | |
79 | - /** |
|
80 | - * @var string |
|
81 | - */ |
|
79 | + /** |
|
80 | + * @var string |
|
81 | + */ |
|
82 | 82 | protected $type; |
83 | 83 | |
84 | - /** |
|
85 | - * @var resource|NULL |
|
86 | - */ |
|
84 | + /** |
|
85 | + * @var resource|NULL |
|
86 | + */ |
|
87 | 87 | protected $newImage; |
88 | 88 | |
89 | - /** |
|
90 | - * @var resource |
|
91 | - */ |
|
89 | + /** |
|
90 | + * @var resource |
|
91 | + */ |
|
92 | 92 | protected $sourceImage; |
93 | 93 | |
94 | - /** |
|
95 | - * @var int |
|
96 | - */ |
|
94 | + /** |
|
95 | + * @var int |
|
96 | + */ |
|
97 | 97 | protected $width; |
98 | 98 | |
99 | - /** |
|
100 | - * @var int |
|
101 | - */ |
|
99 | + /** |
|
100 | + * @var int |
|
101 | + */ |
|
102 | 102 | protected $height; |
103 | 103 | |
104 | - /** |
|
105 | - * @var int |
|
106 | - */ |
|
104 | + /** |
|
105 | + * @var int |
|
106 | + */ |
|
107 | 107 | protected $newWidth = 0; |
108 | 108 | |
109 | - /** |
|
110 | - * @var int |
|
111 | - */ |
|
109 | + /** |
|
110 | + * @var int |
|
111 | + */ |
|
112 | 112 | protected $newHeight = 0; |
113 | 113 | |
114 | - /** |
|
115 | - * @var int |
|
116 | - */ |
|
114 | + /** |
|
115 | + * @var int |
|
116 | + */ |
|
117 | 117 | protected $quality = 85; |
118 | 118 | |
119 | 119 | protected static $imageTypes = array( |
@@ -201,17 +201,17 @@ discard block |
||
201 | 201 | } |
202 | 202 | } |
203 | 203 | |
204 | - /** |
|
205 | - * Factory method: creates a new helper with a blank image. |
|
206 | - * |
|
207 | - * @param integer $width |
|
208 | - * @param integer $height |
|
209 | - * @param string $type The target file type when saving |
|
210 | - * @return ImageHelper |
|
211 | - * @throws ImageHelper_Exception |
|
212 | - * |
|
213 | - * @see ImageHelper::ERROR_CANNOT_CREATE_IMAGE_OBJECT |
|
214 | - */ |
|
204 | + /** |
|
205 | + * Factory method: creates a new helper with a blank image. |
|
206 | + * |
|
207 | + * @param integer $width |
|
208 | + * @param integer $height |
|
209 | + * @param string $type The target file type when saving |
|
210 | + * @return ImageHelper |
|
211 | + * @throws ImageHelper_Exception |
|
212 | + * |
|
213 | + * @see ImageHelper::ERROR_CANNOT_CREATE_IMAGE_OBJECT |
|
214 | + */ |
|
215 | 215 | public static function createNew($width, $height, $type='png') |
216 | 216 | { |
217 | 217 | $img = imagecreatetruecolor($width, $height); |
@@ -226,18 +226,18 @@ discard block |
||
226 | 226 | ); |
227 | 227 | } |
228 | 228 | |
229 | - /** |
|
230 | - * Factory method: creates an image helper from an |
|
231 | - * existing image resource. |
|
232 | - * |
|
233 | - * Note: while the resource is type independent, the |
|
234 | - * type parameter is required for some methods, as well |
|
235 | - * as to be able to save the image. |
|
236 | - * |
|
237 | - * @param resource $resource |
|
238 | - * @param string $type The target image type, e.g. "jpeg", "png", etc. |
|
239 | - * @return ImageHelper |
|
240 | - */ |
|
229 | + /** |
|
230 | + * Factory method: creates an image helper from an |
|
231 | + * existing image resource. |
|
232 | + * |
|
233 | + * Note: while the resource is type independent, the |
|
234 | + * type parameter is required for some methods, as well |
|
235 | + * as to be able to save the image. |
|
236 | + * |
|
237 | + * @param resource $resource |
|
238 | + * @param string $type The target image type, e.g. "jpeg", "png", etc. |
|
239 | + * @return ImageHelper |
|
240 | + */ |
|
241 | 241 | public static function createFromResource($resource, ?string $type=null) |
242 | 242 | { |
243 | 243 | self::requireResource($resource); |
@@ -245,29 +245,29 @@ discard block |
||
245 | 245 | return new ImageHelper(null, $resource, $type); |
246 | 246 | } |
247 | 247 | |
248 | - /** |
|
249 | - * Factory method: creates an image helper from an |
|
250 | - * image file on disk. |
|
251 | - * |
|
252 | - * @param string $path |
|
253 | - * @return ImageHelper |
|
254 | - */ |
|
248 | + /** |
|
249 | + * Factory method: creates an image helper from an |
|
250 | + * image file on disk. |
|
251 | + * |
|
252 | + * @param string $path |
|
253 | + * @return ImageHelper |
|
254 | + */ |
|
255 | 255 | public static function createFromFile($file) |
256 | 256 | { |
257 | 257 | return new ImageHelper($file); |
258 | 258 | } |
259 | 259 | |
260 | - /** |
|
261 | - * Sets a global image helper configuration value. Available |
|
262 | - * configuration settings are: |
|
263 | - * |
|
264 | - * <ul> |
|
265 | - * <li><code>auto-memory-adjustment</code> <i>boolean</i> Whether totry and adjust the memory limit automatically so there will be enough to load/process the target image.</li> |
|
266 | - * </ul> |
|
267 | - * |
|
268 | - * @param string $name |
|
269 | - * @param mixed $value |
|
270 | - */ |
|
260 | + /** |
|
261 | + * Sets a global image helper configuration value. Available |
|
262 | + * configuration settings are: |
|
263 | + * |
|
264 | + * <ul> |
|
265 | + * <li><code>auto-memory-adjustment</code> <i>boolean</i> Whether totry and adjust the memory limit automatically so there will be enough to load/process the target image.</li> |
|
266 | + * </ul> |
|
267 | + * |
|
268 | + * @param string $name |
|
269 | + * @param mixed $value |
|
270 | + */ |
|
271 | 271 | public static function setConfig($name, $value) |
272 | 272 | { |
273 | 273 | if(isset(self::$config[$name])) { |
@@ -275,22 +275,22 @@ discard block |
||
275 | 275 | } |
276 | 276 | } |
277 | 277 | |
278 | - /** |
|
279 | - * Shorthand for setting the automatic memory adjustment |
|
280 | - * global configuration setting. |
|
281 | - * |
|
282 | - * @param bool $enabled |
|
283 | - */ |
|
278 | + /** |
|
279 | + * Shorthand for setting the automatic memory adjustment |
|
280 | + * global configuration setting. |
|
281 | + * |
|
282 | + * @param bool $enabled |
|
283 | + */ |
|
284 | 284 | public static function setAutoMemoryAdjustment($enabled=true) |
285 | 285 | { |
286 | 286 | self::setConfig('auto-memory-adjustment', $enabled); |
287 | 287 | } |
288 | 288 | |
289 | - /** |
|
290 | - * Duplicates an image resource. |
|
291 | - * @param resource $img |
|
292 | - * @return resource |
|
293 | - */ |
|
289 | + /** |
|
290 | + * Duplicates an image resource. |
|
291 | + * @param resource $img |
|
292 | + * @return resource |
|
293 | + */ |
|
294 | 294 | protected function duplicateImage($img) |
295 | 295 | { |
296 | 296 | self::requireResource($img); |
@@ -302,12 +302,12 @@ discard block |
||
302 | 302 | return $duplicate; |
303 | 303 | } |
304 | 304 | |
305 | - /** |
|
306 | - * Duplicates the current state of the image into a new |
|
307 | - * image helper instance. |
|
308 | - * |
|
309 | - * @return ImageHelper |
|
310 | - */ |
|
305 | + /** |
|
306 | + * Duplicates the current state of the image into a new |
|
307 | + * image helper instance. |
|
308 | + * |
|
309 | + * @return ImageHelper |
|
310 | + */ |
|
311 | 311 | public function duplicate() |
312 | 312 | { |
313 | 313 | return ImageHelper::createFromResource($this->duplicateImage($this->newImage)); |
@@ -495,13 +495,13 @@ discard block |
||
495 | 495 | )); |
496 | 496 | } |
497 | 497 | |
498 | - /** |
|
499 | - * Resamples the image to a new width, maintaining |
|
500 | - * aspect ratio. |
|
501 | - * |
|
502 | - * @param int $width |
|
503 | - * @return ImageHelper |
|
504 | - */ |
|
498 | + /** |
|
499 | + * Resamples the image to a new width, maintaining |
|
500 | + * aspect ratio. |
|
501 | + * |
|
502 | + * @param int $width |
|
503 | + * @return ImageHelper |
|
504 | + */ |
|
505 | 505 | public function resampleByWidth(int $width) : ImageHelper |
506 | 506 | { |
507 | 507 | $size = $this->getSizeByWidth($width); |
@@ -511,12 +511,12 @@ discard block |
||
511 | 511 | return $this; |
512 | 512 | } |
513 | 513 | |
514 | - /** |
|
515 | - * Resamples the image by height, and creates a new image file on disk. |
|
516 | - * |
|
517 | - * @param int $height |
|
518 | - * @return ImageHelper |
|
519 | - */ |
|
514 | + /** |
|
515 | + * Resamples the image by height, and creates a new image file on disk. |
|
516 | + * |
|
517 | + * @param int $height |
|
518 | + * @return ImageHelper |
|
519 | + */ |
|
520 | 520 | public function resampleByHeight($height) : ImageHelper |
521 | 521 | { |
522 | 522 | $size = $this->getSizeByHeight($height); |
@@ -524,13 +524,13 @@ discard block |
||
524 | 524 | return $this->resampleImage($size->getWidth(), $size->getHeight()); |
525 | 525 | } |
526 | 526 | |
527 | - /** |
|
528 | - * Resamples the image without keeping the aspect ratio. |
|
529 | - * |
|
530 | - * @param int $width |
|
531 | - * @param int $height |
|
532 | - * @return ImageHelper |
|
533 | - */ |
|
527 | + /** |
|
528 | + * Resamples the image without keeping the aspect ratio. |
|
529 | + * |
|
530 | + * @param int $width |
|
531 | + * @param int $height |
|
532 | + * @return ImageHelper |
|
533 | + */ |
|
534 | 534 | public function resample(?int $width = null, ?int $height = null) : ImageHelper |
535 | 535 | { |
536 | 536 | if($this->isVector()) { |
@@ -595,12 +595,12 @@ discard block |
||
595 | 595 | |
596 | 596 | protected $alpha = false; |
597 | 597 | |
598 | - /** |
|
599 | - * Configures the specified image resource to make it alpha compatible. |
|
600 | - * |
|
601 | - * @param resource $canvas |
|
602 | - * @param bool $fill Whether to fill the whole canvas with the transparency |
|
603 | - */ |
|
598 | + /** |
|
599 | + * Configures the specified image resource to make it alpha compatible. |
|
600 | + * |
|
601 | + * @param resource $canvas |
|
602 | + * @param bool $fill Whether to fill the whole canvas with the transparency |
|
603 | + */ |
|
604 | 604 | public static function addAlphaSupport($canvas, $fill=true) |
605 | 605 | { |
606 | 606 | self::requireResource($canvas); |
@@ -715,12 +715,12 @@ discard block |
||
715 | 715 | $this->quality = $quality * 1; |
716 | 716 | } |
717 | 717 | |
718 | - /** |
|
719 | - * Attempts to adjust the memory to the required size |
|
720 | - * to work with the current image. |
|
721 | - * |
|
722 | - * @return boolean |
|
723 | - */ |
|
718 | + /** |
|
719 | + * Attempts to adjust the memory to the required size |
|
720 | + * to work with the current image. |
|
721 | + * |
|
722 | + * @return boolean |
|
723 | + */ |
|
724 | 724 | protected function adjustMemory() : bool |
725 | 725 | { |
726 | 726 | if(!self::$config['auto-memory-adjustment']) { |
@@ -760,27 +760,27 @@ discard block |
||
760 | 760 | return false; |
761 | 761 | } |
762 | 762 | |
763 | - /** |
|
764 | - * Stretches the image to the specified dimensions. |
|
765 | - * |
|
766 | - * @param int $width |
|
767 | - * @param int $height |
|
768 | - * @return ImageHelper |
|
769 | - */ |
|
763 | + /** |
|
764 | + * Stretches the image to the specified dimensions. |
|
765 | + * |
|
766 | + * @param int $width |
|
767 | + * @param int $height |
|
768 | + * @return ImageHelper |
|
769 | + */ |
|
770 | 770 | public function stretch(int $width, int $height) : ImageHelper |
771 | 771 | { |
772 | 772 | return $this->resampleImage($width, $height); |
773 | 773 | } |
774 | 774 | |
775 | - /** |
|
776 | - * Creates a new image from the current image, |
|
777 | - * resampling it to the new size. |
|
778 | - * |
|
779 | - * @param int $newWidth |
|
780 | - * @param int $newHeight |
|
781 | - * @throws ImageHelper_Exception |
|
782 | - * @return ImageHelper |
|
783 | - */ |
|
775 | + /** |
|
776 | + * Creates a new image from the current image, |
|
777 | + * resampling it to the new size. |
|
778 | + * |
|
779 | + * @param int $newWidth |
|
780 | + * @param int $newHeight |
|
781 | + * @throws ImageHelper_Exception |
|
782 | + * @return ImageHelper |
|
783 | + */ |
|
784 | 784 | protected function resampleImage(int $newWidth, int $newHeight) : ImageHelper |
785 | 785 | { |
786 | 786 | if($this->isVector()) { |
@@ -920,31 +920,31 @@ discard block |
||
920 | 920 | readfile($imageFile); |
921 | 921 | } |
922 | 922 | |
923 | - /** |
|
924 | - * Displays the current image. |
|
925 | - */ |
|
923 | + /** |
|
924 | + * Displays the current image. |
|
925 | + */ |
|
926 | 926 | public function display() |
927 | 927 | { |
928 | 928 | $this->displayImageStream($this->newImage, $this->getType(), $this->resolveQuality()); |
929 | 929 | } |
930 | 930 | |
931 | - /** |
|
932 | - * Trims the current loaded image. |
|
933 | - * |
|
934 | - * @param array $color A color definition, as an associative array with red, green, and blue keys. If not specified, the color at pixel position 0,0 will be used. |
|
935 | - */ |
|
931 | + /** |
|
932 | + * Trims the current loaded image. |
|
933 | + * |
|
934 | + * @param array $color A color definition, as an associative array with red, green, and blue keys. If not specified, the color at pixel position 0,0 will be used. |
|
935 | + */ |
|
936 | 936 | public function trim($color=null) |
937 | 937 | { |
938 | 938 | return $this->trimImage($this->newImage, $color); |
939 | 939 | } |
940 | 940 | |
941 | - /** |
|
942 | - * Retrieves a color definition by its index. |
|
943 | - * |
|
944 | - * @param resource $img A valid image resource. |
|
945 | - * @param int $colorIndex The color index, as returned by imagecolorat for example. |
|
946 | - * @return array An array with red, green, blue and alpha keys. |
|
947 | - */ |
|
941 | + /** |
|
942 | + * Retrieves a color definition by its index. |
|
943 | + * |
|
944 | + * @param resource $img A valid image resource. |
|
945 | + * @param int $colorIndex The color index, as returned by imagecolorat for example. |
|
946 | + * @return array An array with red, green, blue and alpha keys. |
|
947 | + */ |
|
948 | 948 | public function getIndexedColors($img, int $colorIndex) : array |
949 | 949 | { |
950 | 950 | $color = imagecolorsforindex($img, $colorIndex); |
@@ -962,14 +962,14 @@ discard block |
||
962 | 962 | ); |
963 | 963 | } |
964 | 964 | |
965 | - /** |
|
966 | - * Trims the specified image resource by removing the specified color. |
|
967 | - * Also works with transparency. |
|
968 | - * |
|
969 | - * @param resource $img |
|
970 | - * @param array $color A color definition, as an associative array with red, green, blue and alpha keys. If not specified, the color at pixel position 0,0 will be used. |
|
971 | - * @return ImageHelper |
|
972 | - */ |
|
965 | + /** |
|
966 | + * Trims the specified image resource by removing the specified color. |
|
967 | + * Also works with transparency. |
|
968 | + * |
|
969 | + * @param resource $img |
|
970 | + * @param array $color A color definition, as an associative array with red, green, blue and alpha keys. If not specified, the color at pixel position 0,0 will be used. |
|
971 | + * @return ImageHelper |
|
972 | + */ |
|
973 | 973 | protected function trimImage($img, ?array $color=null) : ImageHelper |
974 | 974 | { |
975 | 975 | if($this->isVector()) { |
@@ -1057,12 +1057,12 @@ discard block |
||
1057 | 1057 | return $this; |
1058 | 1058 | } |
1059 | 1059 | |
1060 | - /** |
|
1061 | - * Sets the new image after a transformation operation: |
|
1062 | - * automatically adjusts the new size information. |
|
1063 | - * |
|
1064 | - * @param resource $image |
|
1065 | - */ |
|
1060 | + /** |
|
1061 | + * Sets the new image after a transformation operation: |
|
1062 | + * automatically adjusts the new size information. |
|
1063 | + * |
|
1064 | + * @param resource $image |
|
1065 | + */ |
|
1066 | 1066 | protected function setNewImage($image) |
1067 | 1067 | { |
1068 | 1068 | self::requireResource($image); |
@@ -1072,12 +1072,12 @@ discard block |
||
1072 | 1072 | $this->newHeight= imagesy($image); |
1073 | 1073 | } |
1074 | 1074 | |
1075 | - /** |
|
1076 | - * Requires the subject to be a resource. |
|
1077 | - * |
|
1078 | - * @param resource $subject |
|
1079 | - * @throws ImageHelper_Exception |
|
1080 | - */ |
|
1075 | + /** |
|
1076 | + * Requires the subject to be a resource. |
|
1077 | + * |
|
1078 | + * @param resource $subject |
|
1079 | + * @throws ImageHelper_Exception |
|
1080 | + */ |
|
1081 | 1081 | protected static function requireResource($subject) |
1082 | 1082 | { |
1083 | 1083 | if(is_resource($subject)) { |
@@ -1094,14 +1094,14 @@ discard block |
||
1094 | 1094 | ); |
1095 | 1095 | } |
1096 | 1096 | |
1097 | - /** |
|
1098 | - * Creates a new image resource, with transparent background. |
|
1099 | - * |
|
1100 | - * @param int $width |
|
1101 | - * @param int $height |
|
1102 | - * @throws ImageHelper_Exception |
|
1103 | - * @return resource |
|
1104 | - */ |
|
1097 | + /** |
|
1098 | + * Creates a new image resource, with transparent background. |
|
1099 | + * |
|
1100 | + * @param int $width |
|
1101 | + * @param int $height |
|
1102 | + * @throws ImageHelper_Exception |
|
1103 | + * @return resource |
|
1104 | + */ |
|
1105 | 1105 | protected function createNewImage(int $width, int $height) |
1106 | 1106 | { |
1107 | 1107 | $img = imagecreatetruecolor($width, $height); |
@@ -1120,54 +1120,54 @@ discard block |
||
1120 | 1120 | return $img; |
1121 | 1121 | } |
1122 | 1122 | |
1123 | - /** |
|
1124 | - * Whether the two specified colors are the same. |
|
1125 | - * |
|
1126 | - * @param array $a |
|
1127 | - * @param array $b |
|
1128 | - * @return boolean |
|
1129 | - */ |
|
1130 | - protected function colorsMatch($a, $b) : bool |
|
1131 | - { |
|
1132 | - $parts = array('red', 'green', 'blue'); |
|
1133 | - foreach($parts as $part) { |
|
1134 | - if($a[$part] != $b[$part]) { |
|
1135 | - return false; |
|
1136 | - } |
|
1137 | - } |
|
1123 | + /** |
|
1124 | + * Whether the two specified colors are the same. |
|
1125 | + * |
|
1126 | + * @param array $a |
|
1127 | + * @param array $b |
|
1128 | + * @return boolean |
|
1129 | + */ |
|
1130 | + protected function colorsMatch($a, $b) : bool |
|
1131 | + { |
|
1132 | + $parts = array('red', 'green', 'blue'); |
|
1133 | + foreach($parts as $part) { |
|
1134 | + if($a[$part] != $b[$part]) { |
|
1135 | + return false; |
|
1136 | + } |
|
1137 | + } |
|
1138 | 1138 | |
1139 | - return true; |
|
1140 | - } |
|
1139 | + return true; |
|
1140 | + } |
|
1141 | 1141 | |
1142 | - public function fillWhite($x=0, $y=0) |
|
1143 | - { |
|
1144 | - $this->addRGBColor('white', 255, 255, 255); |
|
1142 | + public function fillWhite($x=0, $y=0) |
|
1143 | + { |
|
1144 | + $this->addRGBColor('white', 255, 255, 255); |
|
1145 | 1145 | return $this->fill('white', $x, $y); |
1146 | - } |
|
1146 | + } |
|
1147 | 1147 | |
1148 | - public function fillTransparent() : ImageHelper |
|
1149 | - { |
|
1148 | + public function fillTransparent() : ImageHelper |
|
1149 | + { |
|
1150 | 1150 | $this->enableAlpha(); |
1151 | 1151 | |
1152 | - self::fillImageTransparent($this->newImage); |
|
1152 | + self::fillImageTransparent($this->newImage); |
|
1153 | 1153 | |
1154 | - return $this; |
|
1155 | - } |
|
1154 | + return $this; |
|
1155 | + } |
|
1156 | 1156 | |
1157 | - public static function fillImageTransparent($resource) |
|
1158 | - { |
|
1159 | - self::requireResource($resource); |
|
1157 | + public static function fillImageTransparent($resource) |
|
1158 | + { |
|
1159 | + self::requireResource($resource); |
|
1160 | 1160 | |
1161 | - $transparent = imagecolorallocatealpha($resource, 89, 14, 207, 127); |
|
1162 | - imagecolortransparent ($resource, $transparent); |
|
1163 | - imagefill($resource, 0, 0, $transparent); |
|
1164 | - } |
|
1161 | + $transparent = imagecolorallocatealpha($resource, 89, 14, 207, 127); |
|
1162 | + imagecolortransparent ($resource, $transparent); |
|
1163 | + imagefill($resource, 0, 0, $transparent); |
|
1164 | + } |
|
1165 | 1165 | |
1166 | - public function fill($colorName, $x=0, $y=0) |
|
1167 | - { |
|
1168 | - imagefill($this->newImage, $x, $y, $this->colors[$colorName]); |
|
1169 | - return $this; |
|
1170 | - } |
|
1166 | + public function fill($colorName, $x=0, $y=0) |
|
1167 | + { |
|
1168 | + imagefill($this->newImage, $x, $y, $this->colors[$colorName]); |
|
1169 | + return $this; |
|
1170 | + } |
|
1171 | 1171 | |
1172 | 1172 | protected $colors = array(); |
1173 | 1173 | |
@@ -1188,9 +1188,9 @@ discard block |
||
1188 | 1188 | return $this; |
1189 | 1189 | } |
1190 | 1190 | |
1191 | - /** |
|
1192 | - * @return resource |
|
1193 | - */ |
|
1191 | + /** |
|
1192 | + * @return resource |
|
1193 | + */ |
|
1194 | 1194 | public function getImage() |
1195 | 1195 | { |
1196 | 1196 | return $this->newImage; |
@@ -1208,27 +1208,27 @@ discard block |
||
1208 | 1208 | return $this; |
1209 | 1209 | } |
1210 | 1210 | |
1211 | - /** |
|
1212 | - * Retrieves the size of the image. |
|
1213 | - * |
|
1214 | - * @param bool $exception Whether to trigger an exception when the image does not exist |
|
1215 | - * @return ImageHelper_Size |
|
1216 | - * @throws ImageHelper_Exception |
|
1217 | - * @see ImageHelper::ERROR_CANNOT_GET_IMAGE_SIZE |
|
1218 | - */ |
|
1219 | - public function getSize() : ImageHelper_Size |
|
1211 | + /** |
|
1212 | + * Retrieves the size of the image. |
|
1213 | + * |
|
1214 | + * @param bool $exception Whether to trigger an exception when the image does not exist |
|
1215 | + * @return ImageHelper_Size |
|
1216 | + * @throws ImageHelper_Exception |
|
1217 | + * @see ImageHelper::ERROR_CANNOT_GET_IMAGE_SIZE |
|
1218 | + */ |
|
1219 | + public function getSize() : ImageHelper_Size |
|
1220 | 1220 | { |
1221 | - return self::getImageSize($this->newImage); |
|
1221 | + return self::getImageSize($this->newImage); |
|
1222 | 1222 | } |
1223 | 1223 | |
1224 | 1224 | protected $TTFFile; |
1225 | 1225 | |
1226 | - /** |
|
1227 | - * Sets the TTF font file to use for text operations. |
|
1228 | - * |
|
1229 | - * @param string $filePath |
|
1230 | - * @return ImageHelper |
|
1231 | - */ |
|
1226 | + /** |
|
1227 | + * Sets the TTF font file to use for text operations. |
|
1228 | + * |
|
1229 | + * @param string $filePath |
|
1230 | + * @return ImageHelper |
|
1231 | + */ |
|
1232 | 1232 | public function setFontTTF($filePath) |
1233 | 1233 | { |
1234 | 1234 | $this->TTFFile = $filePath; |
@@ -1300,63 +1300,63 @@ discard block |
||
1300 | 1300 | return; |
1301 | 1301 | } |
1302 | 1302 | |
1303 | - throw new ImageHelper_Exception( |
|
1303 | + throw new ImageHelper_Exception( |
|
1304 | 1304 | 'No true type font specified', |
1305 | 1305 | 'This functionality requires a TTF font file to be specified with the [setFontTTF] method.', |
1306 | 1306 | self::ERROR_NO_TRUE_TYPE_FONT_SET |
1307 | 1307 | ); |
1308 | 1308 | } |
1309 | 1309 | |
1310 | - /** |
|
1311 | - * Retrieves the size of an image file on disk, or |
|
1312 | - * an existing image resource. |
|
1313 | - * |
|
1314 | - * <pre> |
|
1315 | - * array( |
|
1316 | - * 0: (width), |
|
1317 | - * 1: (height), |
|
1318 | - * "channels": the amount of channels |
|
1319 | - * "bits": bits per channel |
|
1310 | + /** |
|
1311 | + * Retrieves the size of an image file on disk, or |
|
1312 | + * an existing image resource. |
|
1313 | + * |
|
1314 | + * <pre> |
|
1315 | + * array( |
|
1316 | + * 0: (width), |
|
1317 | + * 1: (height), |
|
1318 | + * "channels": the amount of channels |
|
1319 | + * "bits": bits per channel |
|
1320 | 1320 | * ) |
1321 | - * </pre> |
|
1322 | - * |
|
1323 | - * @param string|resource $pathOrResource |
|
1324 | - * @return ImageHelper_Size Size object, can also be accessed like the traditional array from getimagesize |
|
1325 | - * @see ImageHelper_Size |
|
1326 | - * @throws ImageHelper_Exception |
|
1327 | - * @see ImageHelper::ERROR_CANNOT_GET_IMAGE_SIZE |
|
1328 | - * @see ImageHelper::ERROR_CANNOT_READ_SVG_IMAGE |
|
1329 | - * @see ImageHelper::ERROR_SVG_SOURCE_VIEWBOX_MISSING |
|
1330 | - * @see ImageHelper::ERROR_SVG_VIEWBOX_INVALID |
|
1331 | - */ |
|
1332 | - public static function getImageSize($pathOrResource) : ImageHelper_Size |
|
1333 | - { |
|
1334 | - if(is_resource($pathOrResource)) |
|
1335 | - { |
|
1336 | - return new ImageHelper_Size(array( |
|
1337 | - 'width' => imagesx($pathOrResource), |
|
1338 | - 'height' => imagesy($pathOrResource), |
|
1339 | - 'channels' => 1, |
|
1340 | - 'bits' => 8 |
|
1341 | - )); |
|
1342 | - } |
|
1321 | + * </pre> |
|
1322 | + * |
|
1323 | + * @param string|resource $pathOrResource |
|
1324 | + * @return ImageHelper_Size Size object, can also be accessed like the traditional array from getimagesize |
|
1325 | + * @see ImageHelper_Size |
|
1326 | + * @throws ImageHelper_Exception |
|
1327 | + * @see ImageHelper::ERROR_CANNOT_GET_IMAGE_SIZE |
|
1328 | + * @see ImageHelper::ERROR_CANNOT_READ_SVG_IMAGE |
|
1329 | + * @see ImageHelper::ERROR_SVG_SOURCE_VIEWBOX_MISSING |
|
1330 | + * @see ImageHelper::ERROR_SVG_VIEWBOX_INVALID |
|
1331 | + */ |
|
1332 | + public static function getImageSize($pathOrResource) : ImageHelper_Size |
|
1333 | + { |
|
1334 | + if(is_resource($pathOrResource)) |
|
1335 | + { |
|
1336 | + return new ImageHelper_Size(array( |
|
1337 | + 'width' => imagesx($pathOrResource), |
|
1338 | + 'height' => imagesy($pathOrResource), |
|
1339 | + 'channels' => 1, |
|
1340 | + 'bits' => 8 |
|
1341 | + )); |
|
1342 | + } |
|
1343 | 1343 | |
1344 | - $type = self::getFileImageType($pathOrResource); |
|
1344 | + $type = self::getFileImageType($pathOrResource); |
|
1345 | 1345 | |
1346 | - $info = false; |
|
1347 | - $method = 'getImageSize_'.$type; |
|
1348 | - if(method_exists(__CLASS__, $method)) |
|
1349 | - { |
|
1350 | - $info = call_user_func(array(__CLASS__, $method), $pathOrResource); |
|
1351 | - } |
|
1352 | - else |
|
1353 | - { |
|
1354 | - $info = getimagesize($pathOrResource); |
|
1355 | - } |
|
1346 | + $info = false; |
|
1347 | + $method = 'getImageSize_'.$type; |
|
1348 | + if(method_exists(__CLASS__, $method)) |
|
1349 | + { |
|
1350 | + $info = call_user_func(array(__CLASS__, $method), $pathOrResource); |
|
1351 | + } |
|
1352 | + else |
|
1353 | + { |
|
1354 | + $info = getimagesize($pathOrResource); |
|
1355 | + } |
|
1356 | 1356 | |
1357 | - if($info !== false) { |
|
1358 | - return new ImageHelper_Size($info); |
|
1359 | - } |
|
1357 | + if($info !== false) { |
|
1358 | + return new ImageHelper_Size($info); |
|
1359 | + } |
|
1360 | 1360 | |
1361 | 1361 | throw new ImageHelper_Exception( |
1362 | 1362 | 'Error opening image file', |
@@ -1366,96 +1366,96 @@ discard block |
||
1366 | 1366 | ), |
1367 | 1367 | self::ERROR_CANNOT_GET_IMAGE_SIZE |
1368 | 1368 | ); |
1369 | - } |
|
1369 | + } |
|
1370 | 1370 | |
1371 | - /** |
|
1372 | - * @param string $imagePath |
|
1373 | - * @throws ImageHelper_Exception |
|
1374 | - * @return array |
|
1375 | - * |
|
1376 | - * @todo This should return a ImageHelper_Size instance. |
|
1377 | - */ |
|
1378 | - protected static function getImageSize_svg(string $imagePath) : array |
|
1379 | - { |
|
1380 | - $xml = XMLHelper::createSimplexml(); |
|
1381 | - $xml->loadFile($imagePath); |
|
1371 | + /** |
|
1372 | + * @param string $imagePath |
|
1373 | + * @throws ImageHelper_Exception |
|
1374 | + * @return array |
|
1375 | + * |
|
1376 | + * @todo This should return a ImageHelper_Size instance. |
|
1377 | + */ |
|
1378 | + protected static function getImageSize_svg(string $imagePath) : array |
|
1379 | + { |
|
1380 | + $xml = XMLHelper::createSimplexml(); |
|
1381 | + $xml->loadFile($imagePath); |
|
1382 | 1382 | |
1383 | - if($xml->hasErrors()) { |
|
1384 | - throw new ImageHelper_Exception( |
|
1385 | - 'Error opening SVG image', |
|
1386 | - sprintf( |
|
1387 | - 'The XML content of the image [%s] could not be parsed.', |
|
1388 | - $imagePath |
|
1383 | + if($xml->hasErrors()) { |
|
1384 | + throw new ImageHelper_Exception( |
|
1385 | + 'Error opening SVG image', |
|
1386 | + sprintf( |
|
1387 | + 'The XML content of the image [%s] could not be parsed.', |
|
1388 | + $imagePath |
|
1389 | 1389 | ), |
1390 | - self::ERROR_CANNOT_READ_SVG_IMAGE |
|
1390 | + self::ERROR_CANNOT_READ_SVG_IMAGE |
|
1391 | 1391 | ); |
1392 | - } |
|
1392 | + } |
|
1393 | 1393 | |
1394 | - $data = $xml->toArray(); |
|
1395 | - $xml->dispose(); |
|
1396 | - unset($xml); |
|
1394 | + $data = $xml->toArray(); |
|
1395 | + $xml->dispose(); |
|
1396 | + unset($xml); |
|
1397 | 1397 | |
1398 | - if(!isset($data['@attributes']) || !isset($data['@attributes']['viewBox'])) { |
|
1399 | - throw new ImageHelper_Exception( |
|
1400 | - 'SVG Image is corrupted', |
|
1401 | - sprintf( |
|
1402 | - 'The [viewBox] attribute is missing in the XML of the image at path [%s].', |
|
1403 | - $imagePath |
|
1398 | + if(!isset($data['@attributes']) || !isset($data['@attributes']['viewBox'])) { |
|
1399 | + throw new ImageHelper_Exception( |
|
1400 | + 'SVG Image is corrupted', |
|
1401 | + sprintf( |
|
1402 | + 'The [viewBox] attribute is missing in the XML of the image at path [%s].', |
|
1403 | + $imagePath |
|
1404 | 1404 | ), |
1405 | - self::ERROR_SVG_SOURCE_VIEWBOX_MISSING |
|
1405 | + self::ERROR_SVG_SOURCE_VIEWBOX_MISSING |
|
1406 | 1406 | ); |
1407 | - } |
|
1407 | + } |
|
1408 | 1408 | |
1409 | - $svgWidth = parseNumber($data['@attributes']['width'])->getNumber(); |
|
1410 | - $svgHeight = parseNumber($data['@attributes']['height'])->getNumber(); |
|
1409 | + $svgWidth = parseNumber($data['@attributes']['width'])->getNumber(); |
|
1410 | + $svgHeight = parseNumber($data['@attributes']['height'])->getNumber(); |
|
1411 | 1411 | |
1412 | - $viewBox = str_replace(' ', ',', $data['@attributes']['viewBox']); |
|
1413 | - $viewBox = explode(',', $viewBox); |
|
1414 | - if(count($viewBox) != 4) { |
|
1415 | - throw new ImageHelper_Exception( |
|
1416 | - 'SVG image has an invalid viewBox attribute', |
|
1417 | - sprintf( |
|
1418 | - 'The [viewBox] attribute does not have an expected value: [%s] in path [%s].', |
|
1419 | - $viewBox, |
|
1420 | - $imagePath |
|
1412 | + $viewBox = str_replace(' ', ',', $data['@attributes']['viewBox']); |
|
1413 | + $viewBox = explode(',', $viewBox); |
|
1414 | + if(count($viewBox) != 4) { |
|
1415 | + throw new ImageHelper_Exception( |
|
1416 | + 'SVG image has an invalid viewBox attribute', |
|
1417 | + sprintf( |
|
1418 | + 'The [viewBox] attribute does not have an expected value: [%s] in path [%s].', |
|
1419 | + $viewBox, |
|
1420 | + $imagePath |
|
1421 | 1421 | ), |
1422 | - self::ERROR_SVG_VIEWBOX_INVALID |
|
1422 | + self::ERROR_SVG_VIEWBOX_INVALID |
|
1423 | 1423 | ); |
1424 | - } |
|
1424 | + } |
|
1425 | 1425 | |
1426 | - $boxWidth = $viewBox[2]; |
|
1427 | - $boxHeight = $viewBox[3]; |
|
1426 | + $boxWidth = $viewBox[2]; |
|
1427 | + $boxHeight = $viewBox[3]; |
|
1428 | 1428 | |
1429 | - // calculate the x and y units of the document: |
|
1430 | - // @see http://tutorials.jenkov.com/svg/svg-viewport-view-box.html#viewbox |
|
1431 | - // |
|
1432 | - // The viewbox combined with the width and heigt of the svg |
|
1433 | - // allow calculating how many pixels are in one unit of the |
|
1434 | - // width and height of the document. |
|
1429 | + // calculate the x and y units of the document: |
|
1430 | + // @see http://tutorials.jenkov.com/svg/svg-viewport-view-box.html#viewbox |
|
1431 | + // |
|
1432 | + // The viewbox combined with the width and heigt of the svg |
|
1433 | + // allow calculating how many pixels are in one unit of the |
|
1434 | + // width and height of the document. |
|
1435 | 1435 | // |
1436 | - $xUnits = $svgWidth / $boxWidth; |
|
1437 | - $yUnits = $svgHeight / $boxHeight; |
|
1436 | + $xUnits = $svgWidth / $boxWidth; |
|
1437 | + $yUnits = $svgHeight / $boxHeight; |
|
1438 | 1438 | |
1439 | - $pxWidth = $xUnits * $svgWidth; |
|
1440 | - $pxHeight = $yUnits * $svgHeight; |
|
1439 | + $pxWidth = $xUnits * $svgWidth; |
|
1440 | + $pxHeight = $yUnits * $svgHeight; |
|
1441 | 1441 | |
1442 | - return array( |
|
1443 | - $pxWidth, |
|
1444 | - $pxHeight, |
|
1445 | - 'bits' => 8 |
|
1446 | - ); |
|
1447 | - } |
|
1442 | + return array( |
|
1443 | + $pxWidth, |
|
1444 | + $pxHeight, |
|
1445 | + 'bits' => 8 |
|
1446 | + ); |
|
1447 | + } |
|
1448 | 1448 | |
1449 | - /** |
|
1450 | - * Crops the image to the specified width and height, optionally |
|
1451 | - * specifying the origin position to crop from. |
|
1452 | - * |
|
1453 | - * @param integer $width |
|
1454 | - * @param integer $height |
|
1455 | - * @param integer $x |
|
1456 | - * @param integer $y |
|
1457 | - * @return ImageHelper |
|
1458 | - */ |
|
1449 | + /** |
|
1450 | + * Crops the image to the specified width and height, optionally |
|
1451 | + * specifying the origin position to crop from. |
|
1452 | + * |
|
1453 | + * @param integer $width |
|
1454 | + * @param integer $height |
|
1455 | + * @param integer $x |
|
1456 | + * @param integer $y |
|
1457 | + * @return ImageHelper |
|
1458 | + */ |
|
1459 | 1459 | public function crop(int $width, int $height, int $x=0, int $y=0) : ImageHelper |
1460 | 1460 | { |
1461 | 1461 | $new = $this->createNewImage($width, $height); |
@@ -1477,14 +1477,14 @@ discard block |
||
1477 | 1477 | return $this->newHeight; |
1478 | 1478 | } |
1479 | 1479 | |
1480 | - /** |
|
1481 | - * Calculates the average color value used in |
|
1482 | - * the image. Returns an associative array |
|
1483 | - * with the red, green, blue and alpha components. |
|
1484 | - * |
|
1485 | - * @param int $format The format in which to return the color value. |
|
1486 | - * @return array|string |
|
1487 | - */ |
|
1480 | + /** |
|
1481 | + * Calculates the average color value used in |
|
1482 | + * the image. Returns an associative array |
|
1483 | + * with the red, green, blue and alpha components. |
|
1484 | + * |
|
1485 | + * @param int $format The format in which to return the color value. |
|
1486 | + * @return array|string |
|
1487 | + */ |
|
1488 | 1488 | public function calcAverageColor(int $format=self::COLORFORMAT_RGB) |
1489 | 1489 | { |
1490 | 1490 | $image = $this->duplicate(); |
@@ -1507,18 +1507,18 @@ discard block |
||
1507 | 1507 | |
1508 | 1508 | const COLORFORMAT_HEX = 2; |
1509 | 1509 | |
1510 | - /** |
|
1511 | - * Retrieves the color value at the specified pixel |
|
1512 | - * coordinates in the image. |
|
1513 | - * |
|
1514 | - * @param int $x |
|
1515 | - * @param int $y |
|
1516 | - * @param int $format The format in which to return the color value. |
|
1517 | - * @return array|string |
|
1518 | - * |
|
1519 | - * @see ImageHelper::COLORFORMAT_RGB |
|
1520 | - * @see ImageHelper::COLORFORMAT_HEX |
|
1521 | - */ |
|
1510 | + /** |
|
1511 | + * Retrieves the color value at the specified pixel |
|
1512 | + * coordinates in the image. |
|
1513 | + * |
|
1514 | + * @param int $x |
|
1515 | + * @param int $y |
|
1516 | + * @param int $format The format in which to return the color value. |
|
1517 | + * @return array|string |
|
1518 | + * |
|
1519 | + * @see ImageHelper::COLORFORMAT_RGB |
|
1520 | + * @see ImageHelper::COLORFORMAT_HEX |
|
1521 | + */ |
|
1522 | 1522 | public function getColorAt(int $x, int $y, int $format=self::COLORFORMAT_RGB) |
1523 | 1523 | { |
1524 | 1524 | if($x > $this->getWidth() || $y > $this->getHeight()) |
@@ -1546,21 +1546,21 @@ discard block |
||
1546 | 1546 | return $rgb; |
1547 | 1547 | } |
1548 | 1548 | |
1549 | - /** |
|
1550 | - * Converts an RGB value to its luminance equivalent. |
|
1551 | - * |
|
1552 | - * @param array $rgb |
|
1553 | - * @return integer Integer, from 0 to 255 (0=black, 255=white) |
|
1554 | - */ |
|
1549 | + /** |
|
1550 | + * Converts an RGB value to its luminance equivalent. |
|
1551 | + * |
|
1552 | + * @param array $rgb |
|
1553 | + * @return integer Integer, from 0 to 255 (0=black, 255=white) |
|
1554 | + */ |
|
1555 | 1555 | public static function rgb2luma($rgb) |
1556 | 1556 | { |
1557 | 1557 | return (($rgb['red']*2)+$rgb['blue']+($rgb['green']*3))/6; |
1558 | 1558 | } |
1559 | 1559 | |
1560 | - /** |
|
1561 | - * Retrieves the brightness of the image, in percent. |
|
1562 | - * @return number |
|
1563 | - */ |
|
1560 | + /** |
|
1561 | + * Retrieves the brightness of the image, in percent. |
|
1562 | + * @return number |
|
1563 | + */ |
|
1564 | 1564 | public function getBrightness() |
1565 | 1565 | { |
1566 | 1566 | $luma = self::rgb2luma($this->calcAverageColor()); |
@@ -1568,15 +1568,15 @@ discard block |
||
1568 | 1568 | return $percent; |
1569 | 1569 | } |
1570 | 1570 | |
1571 | - /** |
|
1572 | - * Retrieves an md5 hash of the source image file. |
|
1573 | - * |
|
1574 | - * NOTE: Only works when the helper has been created |
|
1575 | - * from a file. Otherwise an exception is thrown. |
|
1576 | - * |
|
1577 | - * @return string |
|
1578 | - * @throws ImageHelper_Exception |
|
1579 | - */ |
|
1571 | + /** |
|
1572 | + * Retrieves an md5 hash of the source image file. |
|
1573 | + * |
|
1574 | + * NOTE: Only works when the helper has been created |
|
1575 | + * from a file. Otherwise an exception is thrown. |
|
1576 | + * |
|
1577 | + * @return string |
|
1578 | + * @throws ImageHelper_Exception |
|
1579 | + */ |
|
1580 | 1580 | public function getHash() |
1581 | 1581 | { |
1582 | 1582 | ob_start(); |
@@ -134,10 +134,10 @@ discard block |
||
134 | 134 | 'gif' |
135 | 135 | ); |
136 | 136 | |
137 | - public function __construct($sourceFile=null, $resource=null, $type=null) |
|
137 | + public function __construct($sourceFile = null, $resource = null, $type = null) |
|
138 | 138 | { |
139 | 139 | // ensure that the GD library is installed |
140 | - if(!function_exists('imagecreate')) |
|
140 | + if (!function_exists('imagecreate')) |
|
141 | 141 | { |
142 | 142 | throw new ImageHelper_Exception( |
143 | 143 | 'The PHP GD extension is not installed or not enabled.', |
@@ -146,7 +146,7 @@ discard block |
||
146 | 146 | ); |
147 | 147 | } |
148 | 148 | |
149 | - if(is_resource($resource)) |
|
149 | + if (is_resource($resource)) |
|
150 | 150 | { |
151 | 151 | $this->sourceImage = $resource; |
152 | 152 | $this->type = $type; |
@@ -170,21 +170,21 @@ discard block |
||
170 | 170 | if (is_null($this->type)) { |
171 | 171 | throw new ImageHelper_Exception( |
172 | 172 | 'Error opening image', |
173 | - 'Not a valid supported image type for image ' . $this->file, |
|
173 | + 'Not a valid supported image type for image '.$this->file, |
|
174 | 174 | self::ERROR_UNSUPPORTED_IMAGE_TYPE |
175 | 175 | ); |
176 | 176 | } |
177 | 177 | |
178 | 178 | $this->info = self::getImageSize($this->file); |
179 | 179 | |
180 | - if(!$this->isVector()) |
|
180 | + if (!$this->isVector()) |
|
181 | 181 | { |
182 | - $method = 'imagecreatefrom' . $this->type; |
|
182 | + $method = 'imagecreatefrom'.$this->type; |
|
183 | 183 | $this->sourceImage = $method($this->file); |
184 | 184 | if (!$this->sourceImage) { |
185 | 185 | throw new ImageHelper_Exception( |
186 | 186 | 'Error creating new image', |
187 | - $method . ' failed', |
|
187 | + $method.' failed', |
|
188 | 188 | self::ERROR_FAILED_TO_CREATE_NEW_IMAGE |
189 | 189 | ); |
190 | 190 | } |
@@ -196,7 +196,7 @@ discard block |
||
196 | 196 | $this->width = $this->info->getWidth(); |
197 | 197 | $this->height = $this->info->getHeight(); |
198 | 198 | |
199 | - if(!$this->isVector()) { |
|
199 | + if (!$this->isVector()) { |
|
200 | 200 | $this->setNewImage($this->duplicateImage($this->sourceImage)); |
201 | 201 | } |
202 | 202 | } |
@@ -212,10 +212,10 @@ discard block |
||
212 | 212 | * |
213 | 213 | * @see ImageHelper::ERROR_CANNOT_CREATE_IMAGE_OBJECT |
214 | 214 | */ |
215 | - public static function createNew($width, $height, $type='png') |
|
215 | + public static function createNew($width, $height, $type = 'png') |
|
216 | 216 | { |
217 | 217 | $img = imagecreatetruecolor($width, $height); |
218 | - if($img !== false) { |
|
218 | + if ($img !== false) { |
|
219 | 219 | return self::createFromResource($img, 'png'); |
220 | 220 | } |
221 | 221 | |
@@ -238,7 +238,7 @@ discard block |
||
238 | 238 | * @param string $type The target image type, e.g. "jpeg", "png", etc. |
239 | 239 | * @return ImageHelper |
240 | 240 | */ |
241 | - public static function createFromResource($resource, ?string $type=null) |
|
241 | + public static function createFromResource($resource, ?string $type = null) |
|
242 | 242 | { |
243 | 243 | self::requireResource($resource); |
244 | 244 | |
@@ -270,7 +270,7 @@ discard block |
||
270 | 270 | */ |
271 | 271 | public static function setConfig($name, $value) |
272 | 272 | { |
273 | - if(isset(self::$config[$name])) { |
|
273 | + if (isset(self::$config[$name])) { |
|
274 | 274 | self::$config[$name] = $value; |
275 | 275 | } |
276 | 276 | } |
@@ -281,7 +281,7 @@ discard block |
||
281 | 281 | * |
282 | 282 | * @param bool $enabled |
283 | 283 | */ |
284 | - public static function setAutoMemoryAdjustment($enabled=true) |
|
284 | + public static function setAutoMemoryAdjustment($enabled = true) |
|
285 | 285 | { |
286 | 286 | self::setConfig('auto-memory-adjustment', $enabled); |
287 | 287 | } |
@@ -315,7 +315,7 @@ discard block |
||
315 | 315 | |
316 | 316 | public function enableAlpha() |
317 | 317 | { |
318 | - if(!$this->alpha) |
|
318 | + if (!$this->alpha) |
|
319 | 319 | { |
320 | 320 | self::addAlphaSupport($this->newImage, false); |
321 | 321 | $this->alpha = true; |
@@ -346,9 +346,9 @@ discard block |
||
346 | 346 | * @param number $percent |
347 | 347 | * @return ImageHelper |
348 | 348 | */ |
349 | - public function sharpen($percent=0) |
|
349 | + public function sharpen($percent = 0) |
|
350 | 350 | { |
351 | - if($percent <= 0) { |
|
351 | + if ($percent <= 0) { |
|
352 | 352 | return $this; |
353 | 353 | } |
354 | 354 | |
@@ -357,9 +357,9 @@ discard block |
||
357 | 357 | return $this->convolute($factor); |
358 | 358 | } |
359 | 359 | |
360 | - public function blur($percent=0) |
|
360 | + public function blur($percent = 0) |
|
361 | 361 | { |
362 | - if($percent <= 0) { |
|
362 | + if ($percent <= 0) { |
|
363 | 363 | return $this; |
364 | 364 | } |
365 | 365 | |
@@ -372,12 +372,12 @@ discard block |
||
372 | 372 | { |
373 | 373 | // get a value thats equal to 64 - abs( factor ) |
374 | 374 | // ( using min/max to limited the factor to 0 - 64 to not get out of range values ) |
375 | - $val1Adjustment = 64 - min( 64, max( 0, abs( $factor ) ) ); |
|
375 | + $val1Adjustment = 64 - min(64, max(0, abs($factor))); |
|
376 | 376 | |
377 | 377 | // the base factor for the "current" pixel depends on if we are blurring or sharpening. |
378 | 378 | // If we are blurring use 1, if sharpening use 9. |
379 | 379 | $val1Base = 9; |
380 | - if( abs( $factor ) != $factor ) { |
|
380 | + if (abs($factor) != $factor) { |
|
381 | 381 | $val1Base = 1; |
382 | 382 | } |
383 | 383 | |
@@ -390,24 +390,24 @@ discard block |
||
390 | 390 | |
391 | 391 | // the value for the surrounding pixels is either positive or negative depending on if we are blurring or sharpening. |
392 | 392 | $val2 = -1; |
393 | - if( abs( $factor ) != $factor ) { |
|
393 | + if (abs($factor) != $factor) { |
|
394 | 394 | $val2 = 1; |
395 | 395 | } |
396 | 396 | |
397 | 397 | // setup matrix .. |
398 | 398 | $matrix = array( |
399 | - array( $val2, $val2, $val2 ), |
|
400 | - array( $val2, $val1, $val2 ), |
|
401 | - array( $val2, $val2, $val2 ) |
|
399 | + array($val2, $val2, $val2), |
|
400 | + array($val2, $val1, $val2), |
|
401 | + array($val2, $val2, $val2) |
|
402 | 402 | ); |
403 | 403 | |
404 | 404 | // calculate the correct divisor |
405 | 405 | // actual divisor is equal to "$divisor = $val1 + $val2 * 8;" |
406 | 406 | // but the following line is more generic |
407 | - $divisor = array_sum( array_map( 'array_sum', $matrix ) ); |
|
407 | + $divisor = array_sum(array_map('array_sum', $matrix)); |
|
408 | 408 | |
409 | 409 | // apply the matrix |
410 | - imageconvolution( $this->newImage, $matrix, $divisor, 0 ); |
|
410 | + imageconvolution($this->newImage, $matrix, $divisor, 0); |
|
411 | 411 | |
412 | 412 | return $this; |
413 | 413 | } |
@@ -533,7 +533,7 @@ discard block |
||
533 | 533 | */ |
534 | 534 | public function resample(?int $width = null, ?int $height = null) : ImageHelper |
535 | 535 | { |
536 | - if($this->isVector()) { |
|
536 | + if ($this->isVector()) { |
|
537 | 537 | return $this; |
538 | 538 | } |
539 | 539 | |
@@ -554,7 +554,7 @@ discard block |
||
554 | 554 | |
555 | 555 | public function resampleAndCrop($width, $height) : ImageHelper |
556 | 556 | { |
557 | - if($this->isVector()) { |
|
557 | + if ($this->isVector()) { |
|
558 | 558 | return $this; |
559 | 559 | } |
560 | 560 | |
@@ -601,14 +601,14 @@ discard block |
||
601 | 601 | * @param resource $canvas |
602 | 602 | * @param bool $fill Whether to fill the whole canvas with the transparency |
603 | 603 | */ |
604 | - public static function addAlphaSupport($canvas, $fill=true) |
|
604 | + public static function addAlphaSupport($canvas, $fill = true) |
|
605 | 605 | { |
606 | 606 | self::requireResource($canvas); |
607 | 607 | |
608 | - imagealphablending($canvas,true); |
|
608 | + imagealphablending($canvas, true); |
|
609 | 609 | imagesavealpha($canvas, true); |
610 | 610 | |
611 | - if($fill) { |
|
611 | + if ($fill) { |
|
612 | 612 | self::fillImageTransparent($canvas); |
613 | 613 | } |
614 | 614 | } |
@@ -618,13 +618,13 @@ discard block |
||
618 | 618 | return $this->alpha; |
619 | 619 | } |
620 | 620 | |
621 | - public function save(string $targetFile, $dispose=true) |
|
621 | + public function save(string $targetFile, $dispose = true) |
|
622 | 622 | { |
623 | - if($this->isVector()) { |
|
623 | + if ($this->isVector()) { |
|
624 | 624 | return true; |
625 | 625 | } |
626 | 626 | |
627 | - if(!is_resource($this->newImage)) { |
|
627 | + if (!is_resource($this->newImage)) { |
|
628 | 628 | throw new ImageHelper_Exception( |
629 | 629 | 'Error creating new image', |
630 | 630 | 'Cannot save an image, no valid image resource was created. You have to call one of the resample methods to create a new image.', |
@@ -636,7 +636,7 @@ discard block |
||
636 | 636 | unlink($targetFile); |
637 | 637 | } |
638 | 638 | |
639 | - $method = 'image' . $this->type; |
|
639 | + $method = 'image'.$this->type; |
|
640 | 640 | if (!$method($this->newImage, $targetFile, $this->resolveQuality())) { |
641 | 641 | throw new ImageHelper_Exception( |
642 | 642 | 'Error creating new image', |
@@ -657,7 +657,7 @@ discard block |
||
657 | 657 | ); |
658 | 658 | } |
659 | 659 | |
660 | - if($dispose) { |
|
660 | + if ($dispose) { |
|
661 | 661 | $this->dispose(); |
662 | 662 | } |
663 | 663 | |
@@ -666,11 +666,11 @@ discard block |
||
666 | 666 | |
667 | 667 | public function dispose() |
668 | 668 | { |
669 | - if(is_resource($this->sourceImage)) { |
|
669 | + if (is_resource($this->sourceImage)) { |
|
670 | 670 | imagedestroy($this->sourceImage); |
671 | 671 | } |
672 | 672 | |
673 | - if(is_resource($this->newImage)) { |
|
673 | + if (is_resource($this->newImage)) { |
|
674 | 674 | imagedestroy($this->newImage); |
675 | 675 | } |
676 | 676 | } |
@@ -723,7 +723,7 @@ discard block |
||
723 | 723 | */ |
724 | 724 | protected function adjustMemory() : bool |
725 | 725 | { |
726 | - if(!self::$config['auto-memory-adjustment']) { |
|
726 | + if (!self::$config['auto-memory-adjustment']) { |
|
727 | 727 | return true; |
728 | 728 | } |
729 | 729 | |
@@ -752,7 +752,7 @@ discard block |
||
752 | 752 | if (function_exists('memory_get_usage') && memory_get_usage() + $memoryNeeded > $memoryLimit) { |
753 | 753 | $newLimit = ($memoryLimit + (memory_get_usage() + $memoryNeeded)) / $MB; |
754 | 754 | $newLimit = ceil($newLimit); |
755 | - ini_set('memory_limit', $newLimit . 'M'); |
|
755 | + ini_set('memory_limit', $newLimit.'M'); |
|
756 | 756 | |
757 | 757 | return true; |
758 | 758 | } |
@@ -783,16 +783,16 @@ discard block |
||
783 | 783 | */ |
784 | 784 | protected function resampleImage(int $newWidth, int $newHeight) : ImageHelper |
785 | 785 | { |
786 | - if($this->isVector()) { |
|
786 | + if ($this->isVector()) { |
|
787 | 787 | return $this; |
788 | 788 | } |
789 | 789 | |
790 | - if($this->newWidth==$newWidth && $this->newHeight==$newHeight) { |
|
790 | + if ($this->newWidth == $newWidth && $this->newHeight == $newHeight) { |
|
791 | 791 | return $this; |
792 | 792 | } |
793 | 793 | |
794 | - if($newWidth < 1) { $newWidth = 1; } |
|
795 | - if($newHeight < 1) { $newHeight = 1; } |
|
794 | + if ($newWidth < 1) { $newWidth = 1; } |
|
795 | + if ($newHeight < 1) { $newHeight = 1; } |
|
796 | 796 | |
797 | 797 | $this->adjustMemory(); |
798 | 798 | |
@@ -856,11 +856,11 @@ discard block |
||
856 | 856 | * @param string $imageType The image format to send, i.e. "jpeg", "png" |
857 | 857 | * @param int $quality The quality to use for the image. This is 0-9 (0=no compression, 9=max) for PNG, and 0-100 (0=lowest, 100=highest quality) for JPG |
858 | 858 | */ |
859 | - public static function displayImageStream($resource, $imageType, $quality=-1) |
|
859 | + public static function displayImageStream($resource, $imageType, $quality = -1) |
|
860 | 860 | { |
861 | 861 | $imageType = strtolower($imageType); |
862 | 862 | |
863 | - if(!in_array($imageType, self::$streamTypes)) { |
|
863 | + if (!in_array($imageType, self::$streamTypes)) { |
|
864 | 864 | throw new ImageHelper_Exception( |
865 | 865 | 'Invalid image stream type', |
866 | 866 | sprintf( |
@@ -871,9 +871,9 @@ discard block |
||
871 | 871 | ); |
872 | 872 | } |
873 | 873 | |
874 | - header('Content-type:image/' . $imageType); |
|
874 | + header('Content-type:image/'.$imageType); |
|
875 | 875 | |
876 | - $function = 'image' . $imageType; |
|
876 | + $function = 'image'.$imageType; |
|
877 | 877 | |
878 | 878 | $function($resource, null, $quality); |
879 | 879 | } |
@@ -889,7 +889,7 @@ discard block |
||
889 | 889 | if (headers_sent($file, $line)) { |
890 | 890 | throw new ImageHelper_Exception( |
891 | 891 | 'Error displaying image', |
892 | - 'Headers have already been sent: in file ' . $file . ':' . $line, |
|
892 | + 'Headers have already been sent: in file '.$file.':'.$line, |
|
893 | 893 | self::ERROR_HEADERS_ALREADY_SENT |
894 | 894 | ); |
895 | 895 | } |
@@ -906,16 +906,16 @@ discard block |
||
906 | 906 | } |
907 | 907 | |
908 | 908 | $format = self::getFileImageType($imageFile); |
909 | - if($format == 'svg') { |
|
909 | + if ($format == 'svg') { |
|
910 | 910 | $format = 'svg+xml'; |
911 | 911 | } |
912 | 912 | |
913 | - $contentType = 'image/' . $format; |
|
913 | + $contentType = 'image/'.$format; |
|
914 | 914 | |
915 | 915 | header('Content-Type: '.$contentType); |
916 | - header("Last-Modified: " . gmdate("D, d M Y H:i:s", filemtime($imageFile)) . " GMT"); |
|
916 | + header("Last-Modified: ".gmdate("D, d M Y H:i:s", filemtime($imageFile))." GMT"); |
|
917 | 917 | header('Cache-Control: public'); |
918 | - header('Content-Length: ' . filesize($imageFile)); |
|
918 | + header('Content-Length: '.filesize($imageFile)); |
|
919 | 919 | |
920 | 920 | readfile($imageFile); |
921 | 921 | } |
@@ -933,7 +933,7 @@ discard block |
||
933 | 933 | * |
934 | 934 | * @param array $color A color definition, as an associative array with red, green, and blue keys. If not specified, the color at pixel position 0,0 will be used. |
935 | 935 | */ |
936 | - public function trim($color=null) |
|
936 | + public function trim($color = null) |
|
937 | 937 | { |
938 | 938 | return $this->trimImage($this->newImage, $color); |
939 | 939 | } |
@@ -950,7 +950,7 @@ discard block |
||
950 | 950 | $color = imagecolorsforindex($img, $colorIndex); |
951 | 951 | |
952 | 952 | // it seems imagecolorsforindex may return false (undocumented, unproven) |
953 | - if(is_array($color)) { |
|
953 | + if (is_array($color)) { |
|
954 | 954 | return $color; |
955 | 955 | } |
956 | 956 | |
@@ -970,15 +970,15 @@ discard block |
||
970 | 970 | * @param array $color A color definition, as an associative array with red, green, blue and alpha keys. If not specified, the color at pixel position 0,0 will be used. |
971 | 971 | * @return ImageHelper |
972 | 972 | */ |
973 | - protected function trimImage($img, ?array $color=null) : ImageHelper |
|
973 | + protected function trimImage($img, ?array $color = null) : ImageHelper |
|
974 | 974 | { |
975 | - if($this->isVector()) { |
|
975 | + if ($this->isVector()) { |
|
976 | 976 | return $this; |
977 | 977 | } |
978 | 978 | |
979 | 979 | self::requireResource($img); |
980 | 980 | |
981 | - if(empty($color)) |
|
981 | + if (empty($color)) |
|
982 | 982 | { |
983 | 983 | $color = imagecolorat($img, 0, 0); |
984 | 984 | $color = $this->getIndexedColors($img, $color); |
@@ -995,16 +995,16 @@ discard block |
||
995 | 995 | $ymax = null; |
996 | 996 | |
997 | 997 | // Start scanning for the edges. |
998 | - for ($iy=0; $iy<$imh; $iy++) |
|
998 | + for ($iy = 0; $iy < $imh; $iy++) |
|
999 | 999 | { |
1000 | 1000 | $first = true; |
1001 | 1001 | |
1002 | - for ($ix=0; $ix<$imw; $ix++) |
|
1002 | + for ($ix = 0; $ix < $imw; $ix++) |
|
1003 | 1003 | { |
1004 | 1004 | $ndx = imagecolorat($img, $ix, $iy); |
1005 | 1005 | $colors = $this->getIndexedColors($img, $ndx); |
1006 | 1006 | |
1007 | - if(!$this->colorsMatch($colors, $color)) |
|
1007 | + if (!$this->colorsMatch($colors, $color)) |
|
1008 | 1008 | { |
1009 | 1009 | if ($xmin > $ix) { $xmin = $ix; } |
1010 | 1010 | if ($xmax < $ix) { $xmax = $ix; } |
@@ -1012,7 +1012,7 @@ discard block |
||
1012 | 1012 | |
1013 | 1013 | $ymax = $iy; |
1014 | 1014 | |
1015 | - if($first) |
|
1015 | + if ($first) |
|
1016 | 1016 | { |
1017 | 1017 | $ix = $xmax; |
1018 | 1018 | $first = false; |
@@ -1022,18 +1022,18 @@ discard block |
||
1022 | 1022 | } |
1023 | 1023 | |
1024 | 1024 | // no trimming border found |
1025 | - if($ymax === null && $ymax === null) { |
|
1025 | + if ($ymax === null && $ymax === null) { |
|
1026 | 1026 | return $this; |
1027 | 1027 | } |
1028 | 1028 | |
1029 | 1029 | // The new width and height of the image. |
1030 | - $imw = 1+$xmax-$xmin; // Image width in pixels |
|
1031 | - $imh = 1+$ymax-$ymin; // Image height in pixels |
|
1030 | + $imw = 1 + $xmax - $xmin; // Image width in pixels |
|
1031 | + $imh = 1 + $ymax - $ymin; // Image height in pixels |
|
1032 | 1032 | |
1033 | 1033 | // Make another image to place the trimmed version in. |
1034 | 1034 | $im2 = $this->createNewImage($imw, $imh); |
1035 | 1035 | |
1036 | - if($color['alpha'] > 0) |
|
1036 | + if ($color['alpha'] > 0) |
|
1037 | 1037 | { |
1038 | 1038 | $bg2 = imagecolorallocatealpha($im2, $color['red'], $color['green'], $color['blue'], $color['alpha']); |
1039 | 1039 | imagecolortransparent($im2, $bg2); |
@@ -1069,7 +1069,7 @@ discard block |
||
1069 | 1069 | |
1070 | 1070 | $this->newImage = $image; |
1071 | 1071 | $this->newWidth = imagesx($image); |
1072 | - $this->newHeight= imagesy($image); |
|
1072 | + $this->newHeight = imagesy($image); |
|
1073 | 1073 | } |
1074 | 1074 | |
1075 | 1075 | /** |
@@ -1080,7 +1080,7 @@ discard block |
||
1080 | 1080 | */ |
1081 | 1081 | protected static function requireResource($subject) |
1082 | 1082 | { |
1083 | - if(is_resource($subject)) { |
|
1083 | + if (is_resource($subject)) { |
|
1084 | 1084 | return; |
1085 | 1085 | } |
1086 | 1086 | |
@@ -1106,7 +1106,7 @@ discard block |
||
1106 | 1106 | { |
1107 | 1107 | $img = imagecreatetruecolor($width, $height); |
1108 | 1108 | |
1109 | - if($img === false) |
|
1109 | + if ($img === false) |
|
1110 | 1110 | { |
1111 | 1111 | throw new ImageHelper_Exception( |
1112 | 1112 | 'Error creating new image', |
@@ -1130,8 +1130,8 @@ discard block |
||
1130 | 1130 | protected function colorsMatch($a, $b) : bool |
1131 | 1131 | { |
1132 | 1132 | $parts = array('red', 'green', 'blue'); |
1133 | - foreach($parts as $part) { |
|
1134 | - if($a[$part] != $b[$part]) { |
|
1133 | + foreach ($parts as $part) { |
|
1134 | + if ($a[$part] != $b[$part]) { |
|
1135 | 1135 | return false; |
1136 | 1136 | } |
1137 | 1137 | } |
@@ -1139,7 +1139,7 @@ discard block |
||
1139 | 1139 | return true; |
1140 | 1140 | } |
1141 | 1141 | |
1142 | - public function fillWhite($x=0, $y=0) |
|
1142 | + public function fillWhite($x = 0, $y = 0) |
|
1143 | 1143 | { |
1144 | 1144 | $this->addRGBColor('white', 255, 255, 255); |
1145 | 1145 | return $this->fill('white', $x, $y); |
@@ -1159,11 +1159,11 @@ discard block |
||
1159 | 1159 | self::requireResource($resource); |
1160 | 1160 | |
1161 | 1161 | $transparent = imagecolorallocatealpha($resource, 89, 14, 207, 127); |
1162 | - imagecolortransparent ($resource, $transparent); |
|
1162 | + imagecolortransparent($resource, $transparent); |
|
1163 | 1163 | imagefill($resource, 0, 0, $transparent); |
1164 | 1164 | } |
1165 | 1165 | |
1166 | - public function fill($colorName, $x=0, $y=0) |
|
1166 | + public function fill($colorName, $x = 0, $y = 0) |
|
1167 | 1167 | { |
1168 | 1168 | imagefill($this->newImage, $x, $y, $this->colors[$colorName]); |
1169 | 1169 | return $this; |
@@ -1177,7 +1177,7 @@ discard block |
||
1177 | 1177 | return $this; |
1178 | 1178 | } |
1179 | 1179 | |
1180 | - public function textTTF($text, $size, $colorName, $x=0, $y=0, $angle=0) |
|
1180 | + public function textTTF($text, $size, $colorName, $x = 0, $y = 0, $angle = 0) |
|
1181 | 1181 | { |
1182 | 1182 | imagealphablending($this->newImage, true); |
1183 | 1183 | |
@@ -1196,11 +1196,11 @@ discard block |
||
1196 | 1196 | return $this->newImage; |
1197 | 1197 | } |
1198 | 1198 | |
1199 | - public function paste(ImageHelper $target, $xpos=0, $ypos=0, $sourceX=0, $sourceY=0) |
|
1199 | + public function paste(ImageHelper $target, $xpos = 0, $ypos = 0, $sourceX = 0, $sourceY = 0) |
|
1200 | 1200 | { |
1201 | 1201 | $img = $target->getImage(); |
1202 | 1202 | |
1203 | - if($target->isAlpha()) { |
|
1203 | + if ($target->isAlpha()) { |
|
1204 | 1204 | $this->enableAlpha(); |
1205 | 1205 | } |
1206 | 1206 | |
@@ -1246,10 +1246,10 @@ discard block |
||
1246 | 1246 | public function fitText($text, $matchWidth) |
1247 | 1247 | { |
1248 | 1248 | $sizes = array(); |
1249 | - for($i=1; $i<=1000; $i=$i+0.1) { |
|
1249 | + for ($i = 1; $i <= 1000; $i = $i + 0.1) { |
|
1250 | 1250 | $size = $this->calcTextSize($text, $i); |
1251 | 1251 | $sizes[] = $size; |
1252 | - if($size['width'] >= $matchWidth) { |
|
1252 | + if ($size['width'] >= $matchWidth) { |
|
1253 | 1253 | break; |
1254 | 1254 | } |
1255 | 1255 | } |
@@ -1261,7 +1261,7 @@ discard block |
||
1261 | 1261 | $diffLast = $last['width'] - $matchWidth; |
1262 | 1262 | $diffPrev = $matchWidth - $prev['width']; |
1263 | 1263 | |
1264 | - if($diffLast <= $diffPrev) { |
|
1264 | + if ($diffLast <= $diffPrev) { |
|
1265 | 1265 | return $last; |
1266 | 1266 | } |
1267 | 1267 | |
@@ -1289,14 +1289,14 @@ discard block |
||
1289 | 1289 | 'bottom_left_y' => $box[1], |
1290 | 1290 | 'bottom_right_x' => $box[2], |
1291 | 1291 | 'bottom_right_y' => $box[3], |
1292 | - 'width' => $right-$left, |
|
1293 | - 'height' => $bottom-$top |
|
1292 | + 'width' => $right - $left, |
|
1293 | + 'height' => $bottom - $top |
|
1294 | 1294 | ); |
1295 | 1295 | } |
1296 | 1296 | |
1297 | 1297 | protected function requireTTFFont() |
1298 | 1298 | { |
1299 | - if(isset($this->TTFFile)) { |
|
1299 | + if (isset($this->TTFFile)) { |
|
1300 | 1300 | return; |
1301 | 1301 | } |
1302 | 1302 | |
@@ -1331,7 +1331,7 @@ discard block |
||
1331 | 1331 | */ |
1332 | 1332 | public static function getImageSize($pathOrResource) : ImageHelper_Size |
1333 | 1333 | { |
1334 | - if(is_resource($pathOrResource)) |
|
1334 | + if (is_resource($pathOrResource)) |
|
1335 | 1335 | { |
1336 | 1336 | return new ImageHelper_Size(array( |
1337 | 1337 | 'width' => imagesx($pathOrResource), |
@@ -1345,7 +1345,7 @@ discard block |
||
1345 | 1345 | |
1346 | 1346 | $info = false; |
1347 | 1347 | $method = 'getImageSize_'.$type; |
1348 | - if(method_exists(__CLASS__, $method)) |
|
1348 | + if (method_exists(__CLASS__, $method)) |
|
1349 | 1349 | { |
1350 | 1350 | $info = call_user_func(array(__CLASS__, $method), $pathOrResource); |
1351 | 1351 | } |
@@ -1354,7 +1354,7 @@ discard block |
||
1354 | 1354 | $info = getimagesize($pathOrResource); |
1355 | 1355 | } |
1356 | 1356 | |
1357 | - if($info !== false) { |
|
1357 | + if ($info !== false) { |
|
1358 | 1358 | return new ImageHelper_Size($info); |
1359 | 1359 | } |
1360 | 1360 | |
@@ -1380,7 +1380,7 @@ discard block |
||
1380 | 1380 | $xml = XMLHelper::createSimplexml(); |
1381 | 1381 | $xml->loadFile($imagePath); |
1382 | 1382 | |
1383 | - if($xml->hasErrors()) { |
|
1383 | + if ($xml->hasErrors()) { |
|
1384 | 1384 | throw new ImageHelper_Exception( |
1385 | 1385 | 'Error opening SVG image', |
1386 | 1386 | sprintf( |
@@ -1395,7 +1395,7 @@ discard block |
||
1395 | 1395 | $xml->dispose(); |
1396 | 1396 | unset($xml); |
1397 | 1397 | |
1398 | - if(!isset($data['@attributes']) || !isset($data['@attributes']['viewBox'])) { |
|
1398 | + if (!isset($data['@attributes']) || !isset($data['@attributes']['viewBox'])) { |
|
1399 | 1399 | throw new ImageHelper_Exception( |
1400 | 1400 | 'SVG Image is corrupted', |
1401 | 1401 | sprintf( |
@@ -1411,7 +1411,7 @@ discard block |
||
1411 | 1411 | |
1412 | 1412 | $viewBox = str_replace(' ', ',', $data['@attributes']['viewBox']); |
1413 | 1413 | $viewBox = explode(',', $viewBox); |
1414 | - if(count($viewBox) != 4) { |
|
1414 | + if (count($viewBox) != 4) { |
|
1415 | 1415 | throw new ImageHelper_Exception( |
1416 | 1416 | 'SVG image has an invalid viewBox attribute', |
1417 | 1417 | sprintf( |
@@ -1456,7 +1456,7 @@ discard block |
||
1456 | 1456 | * @param integer $y |
1457 | 1457 | * @return ImageHelper |
1458 | 1458 | */ |
1459 | - public function crop(int $width, int $height, int $x=0, int $y=0) : ImageHelper |
|
1459 | + public function crop(int $width, int $height, int $x = 0, int $y = 0) : ImageHelper |
|
1460 | 1460 | { |
1461 | 1461 | $new = $this->createNewImage($width, $height); |
1462 | 1462 | |
@@ -1485,7 +1485,7 @@ discard block |
||
1485 | 1485 | * @param int $format The format in which to return the color value. |
1486 | 1486 | * @return array|string |
1487 | 1487 | */ |
1488 | - public function calcAverageColor(int $format=self::COLORFORMAT_RGB) |
|
1488 | + public function calcAverageColor(int $format = self::COLORFORMAT_RGB) |
|
1489 | 1489 | { |
1490 | 1490 | $image = $this->duplicate(); |
1491 | 1491 | $image->resample(1, 1); |
@@ -1519,9 +1519,9 @@ discard block |
||
1519 | 1519 | * @see ImageHelper::COLORFORMAT_RGB |
1520 | 1520 | * @see ImageHelper::COLORFORMAT_HEX |
1521 | 1521 | */ |
1522 | - public function getColorAt(int $x, int $y, int $format=self::COLORFORMAT_RGB) |
|
1522 | + public function getColorAt(int $x, int $y, int $format = self::COLORFORMAT_RGB) |
|
1523 | 1523 | { |
1524 | - if($x > $this->getWidth() || $y > $this->getHeight()) |
|
1524 | + if ($x > $this->getWidth() || $y > $this->getHeight()) |
|
1525 | 1525 | { |
1526 | 1526 | throw new ImageHelper_Exception( |
1527 | 1527 | 'Position out of bounds', |
@@ -1539,7 +1539,7 @@ discard block |
||
1539 | 1539 | $idx = imagecolorat($this->newImage, $x, $y); |
1540 | 1540 | $rgb = $this->getIndexedColors($this->newImage, $idx); |
1541 | 1541 | |
1542 | - if($format == self::COLORFORMAT_HEX) { |
|
1542 | + if ($format == self::COLORFORMAT_HEX) { |
|
1543 | 1543 | return self::rgb2hex($rgb); |
1544 | 1544 | } |
1545 | 1545 | |
@@ -1554,7 +1554,7 @@ discard block |
||
1554 | 1554 | */ |
1555 | 1555 | public static function rgb2luma($rgb) |
1556 | 1556 | { |
1557 | - return (($rgb['red']*2)+$rgb['blue']+($rgb['green']*3))/6; |
|
1557 | + return (($rgb['red'] * 2) + $rgb['blue'] + ($rgb['green'] * 3)) / 6; |
|
1558 | 1558 | } |
1559 | 1559 | |
1560 | 1560 | /** |
@@ -151,8 +151,7 @@ discard block |
||
151 | 151 | $this->sourceImage = $resource; |
152 | 152 | $this->type = $type; |
153 | 153 | $this->info = self::getImageSize($resource); |
154 | - } |
|
155 | - else |
|
154 | + } else |
|
156 | 155 | { |
157 | 156 | $this->file = $sourceFile; |
158 | 157 | if (!file_exists($this->file)) { |
@@ -561,8 +560,7 @@ discard block |
||
561 | 560 | if ($this->width <= $this->height) |
562 | 561 | { |
563 | 562 | $this->resampleByWidth($width); |
564 | - } |
|
565 | - else |
|
563 | + } else |
|
566 | 564 | { |
567 | 565 | $this->resampleByHeight($height); |
568 | 566 | } |
@@ -1037,8 +1035,7 @@ discard block |
||
1037 | 1035 | { |
1038 | 1036 | $bg2 = imagecolorallocatealpha($im2, $color['red'], $color['green'], $color['blue'], $color['alpha']); |
1039 | 1037 | imagecolortransparent($im2, $bg2); |
1040 | - } |
|
1041 | - else |
|
1038 | + } else |
|
1042 | 1039 | { |
1043 | 1040 | $bg2 = imagecolorallocate($im2, $color['red'], $color['green'], $color['blue']); |
1044 | 1041 | } |
@@ -1348,8 +1345,7 @@ discard block |
||
1348 | 1345 | if(method_exists(__CLASS__, $method)) |
1349 | 1346 | { |
1350 | 1347 | $info = call_user_func(array(__CLASS__, $method), $pathOrResource); |
1351 | - } |
|
1352 | - else |
|
1348 | + } else |
|
1353 | 1349 | { |
1354 | 1350 | $info = getimagesize($pathOrResource); |
1355 | 1351 | } |