@@ -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 | /** |