@@ -6,7 +6,7 @@ |
||
| 6 | 6 | |
| 7 | 7 | declare(strict_types=1); |
| 8 | 8 | |
| 9 | -if(!class_exists('CurlHandle')) |
|
| 9 | +if (!class_exists('CurlHandle')) |
|
| 10 | 10 | { |
| 11 | 11 | /** |
| 12 | 12 | * Shim to support PHPStan analysis on PHP7, while |
@@ -6,7 +6,7 @@ |
||
| 6 | 6 | |
| 7 | 7 | declare(strict_types=1); |
| 8 | 8 | |
| 9 | -if(!class_exists('GdImage')) |
|
| 9 | +if (!class_exists('GdImage')) |
|
| 10 | 10 | { |
| 11 | 11 | /** |
| 12 | 12 | * Shim to support PHPStan analysis on PHP7, while |
@@ -25,7 +25,7 @@ |
||
| 25 | 25 | interface PathInfoInterface extends Interface_Stringable |
| 26 | 26 | { |
| 27 | 27 | public function getName() : string; |
| 28 | - public function getExtension(bool $lowercase=true) : string; |
|
| 28 | + public function getExtension(bool $lowercase = true) : string; |
|
| 29 | 29 | public function getPath() : string; |
| 30 | 30 | public function getFolderPath() : string; |
| 31 | 31 | public function exists() : bool; |
@@ -41,7 +41,7 @@ discard block |
||
| 41 | 41 | */ |
| 42 | 42 | public function setTimeout(int $timeout) : FileDownloader |
| 43 | 43 | { |
| 44 | - if($timeout > 0) |
|
| 44 | + if ($timeout > 0) |
|
| 45 | 45 | { |
| 46 | 46 | $this->timeout = $timeout; |
| 47 | 47 | } |
@@ -53,7 +53,7 @@ discard block |
||
| 53 | 53 | * @param bool $enabled |
| 54 | 54 | * @return FileDownloader |
| 55 | 55 | */ |
| 56 | - public function setSSLEnabled(bool $enabled=true) : FileDownloader |
|
| 56 | + public function setSSLEnabled(bool $enabled = true) : FileDownloader |
|
| 57 | 57 | { |
| 58 | 58 | $this->SSLEnabled = $enabled; |
| 59 | 59 | return $this; |
@@ -74,7 +74,7 @@ discard block |
||
| 74 | 74 | |
| 75 | 75 | $output = curl_exec($ch); |
| 76 | 76 | |
| 77 | - if($output === false) |
|
| 77 | + if ($output === false) |
|
| 78 | 78 | { |
| 79 | 79 | throw new FileHelper_Exception( |
| 80 | 80 | 'Unable to open URL', |
@@ -89,7 +89,7 @@ discard block |
||
| 89 | 89 | |
| 90 | 90 | curl_close($ch); |
| 91 | 91 | |
| 92 | - if(is_string($output)) |
|
| 92 | + if (is_string($output)) |
|
| 93 | 93 | { |
| 94 | 94 | return $output; |
| 95 | 95 | } |
@@ -117,7 +117,7 @@ discard block |
||
| 117 | 117 | curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); |
| 118 | 118 | curl_setopt($ch, CURLOPT_TIMEOUT, $this->timeout); |
| 119 | 119 | |
| 120 | - if(!$this->SSLEnabled) |
|
| 120 | + if (!$this->SSLEnabled) |
|
| 121 | 121 | { |
| 122 | 122 | curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); |
| 123 | 123 | curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0); |
@@ -11,17 +11,17 @@ discard block |
||
| 11 | 11 | |
| 12 | 12 | abstract class ColorContainer extends StyleContainer |
| 13 | 13 | { |
| 14 | - public function rgbaValues(int $red, int $green, int $blue, float $alpha=0) : StyleBuilder |
|
| 14 | + public function rgbaValues(int $red, int $green, int $blue, float $alpha = 0) : StyleBuilder |
|
| 15 | 15 | { |
| 16 | 16 | return $this->rgba(ColorFactory::createCSS($red, $green, $blue, $alpha)); |
| 17 | 17 | } |
| 18 | 18 | |
| 19 | - public function rgba(RGBAColor $color, bool $important=false) : StyleBuilder |
|
| 19 | + public function rgba(RGBAColor $color, bool $important = false) : StyleBuilder |
|
| 20 | 20 | { |
| 21 | 21 | return $this->setStyle($color->toCSS(), $important); |
| 22 | 22 | } |
| 23 | 23 | |
| 24 | - public function hex(RGBAColor $color, bool $important=false) : StyleBuilder |
|
| 24 | + public function hex(RGBAColor $color, bool $important = false) : StyleBuilder |
|
| 25 | 25 | { |
| 26 | 26 | return $this->setStyle('#'.$color->toHEX(), $important); |
| 27 | 27 | } |
@@ -34,7 +34,7 @@ discard block |
||
| 34 | 34 | * @return StyleBuilder |
| 35 | 35 | * @throws ColorException |
| 36 | 36 | */ |
| 37 | - public function hexString(string $hex, bool $important=false) : StyleBuilder |
|
| 37 | + public function hexString(string $hex, bool $important = false) : StyleBuilder |
|
| 38 | 38 | { |
| 39 | 39 | return $this->hex(ColorFactory::createFromHEX($hex), $important); |
| 40 | 40 | } |
@@ -73,13 +73,13 @@ discard block |
||
| 73 | 73 | protected array $colors = array(); |
| 74 | 74 | |
| 75 | 75 | /** |
| 76 | - * @var resource|NULL |
|
| 77 | - */ |
|
| 76 | + * @var resource|NULL |
|
| 77 | + */ |
|
| 78 | 78 | protected $newImage; |
| 79 | 79 | |
| 80 | - /** |
|
| 81 | - * @var resource |
|
| 82 | - */ |
|
| 80 | + /** |
|
| 81 | + * @var resource |
|
| 82 | + */ |
|
| 83 | 83 | protected $sourceImage; |
| 84 | 84 | |
| 85 | 85 | /** |
@@ -188,17 +188,17 @@ discard block |
||
| 188 | 188 | } |
| 189 | 189 | } |
| 190 | 190 | |
| 191 | - /** |
|
| 192 | - * Factory method: creates a new helper with a blank image. |
|
| 193 | - * |
|
| 194 | - * @param integer $width |
|
| 195 | - * @param integer $height |
|
| 196 | - * @param string $type The target file type when saving |
|
| 197 | - * @return ImageHelper |
|
| 198 | - * @throws ImageHelper_Exception |
|
| 199 | - * |
|
| 200 | - * @see ImageHelper::ERROR_CANNOT_CREATE_IMAGE_OBJECT |
|
| 201 | - */ |
|
| 191 | + /** |
|
| 192 | + * Factory method: creates a new helper with a blank image. |
|
| 193 | + * |
|
| 194 | + * @param integer $width |
|
| 195 | + * @param integer $height |
|
| 196 | + * @param string $type The target file type when saving |
|
| 197 | + * @return ImageHelper |
|
| 198 | + * @throws ImageHelper_Exception |
|
| 199 | + * |
|
| 200 | + * @see ImageHelper::ERROR_CANNOT_CREATE_IMAGE_OBJECT |
|
| 201 | + */ |
|
| 202 | 202 | public static function createNew(int $width, int $height, string $type='png') : self |
| 203 | 203 | { |
| 204 | 204 | $img = imagecreatetruecolor($width, $height); |
@@ -249,17 +249,17 @@ discard block |
||
| 249 | 249 | return new ImageHelper($file, null, self::getFileImageType($file)); |
| 250 | 250 | } |
| 251 | 251 | |
| 252 | - /** |
|
| 253 | - * Sets a global image helper configuration value. Available |
|
| 254 | - * configuration settings are: |
|
| 255 | - * |
|
| 256 | - * <ul> |
|
| 257 | - * <li><code>auto-memory-adjustment</code> <i>boolean</i> Whether to try and adjust the memory limit automatically so there will be enough to load/process the target image.</li> |
|
| 258 | - * </ul> |
|
| 259 | - * |
|
| 260 | - * @param string $name |
|
| 261 | - * @param mixed|NULL $value |
|
| 262 | - */ |
|
| 252 | + /** |
|
| 253 | + * Sets a global image helper configuration value. Available |
|
| 254 | + * configuration settings are: |
|
| 255 | + * |
|
| 256 | + * <ul> |
|
| 257 | + * <li><code>auto-memory-adjustment</code> <i>boolean</i> Whether to try and adjust the memory limit automatically so there will be enough to load/process the target image.</li> |
|
| 258 | + * </ul> |
|
| 259 | + * |
|
| 260 | + * @param string $name |
|
| 261 | + * @param mixed|NULL $value |
|
| 262 | + */ |
|
| 263 | 263 | public static function setConfig(string $name, $value) : void |
| 264 | 264 | { |
| 265 | 265 | if(isset(self::$config[$name])) { |
@@ -267,13 +267,13 @@ discard block |
||
| 267 | 267 | } |
| 268 | 268 | } |
| 269 | 269 | |
| 270 | - /** |
|
| 271 | - * Shorthand for setting the automatic memory adjustment |
|
| 272 | - * global configuration setting. |
|
| 273 | - * |
|
| 274 | - * @param bool $enabled |
|
| 275 | - * @return void |
|
| 276 | - */ |
|
| 270 | + /** |
|
| 271 | + * Shorthand for setting the automatic memory adjustment |
|
| 272 | + * global configuration setting. |
|
| 273 | + * |
|
| 274 | + * @param bool $enabled |
|
| 275 | + * @return void |
|
| 276 | + */ |
|
| 277 | 277 | public static function setAutoMemoryAdjustment(bool $enabled=true) : void |
| 278 | 278 | { |
| 279 | 279 | self::setConfig('auto-memory-adjustment', $enabled); |
@@ -747,12 +747,12 @@ discard block |
||
| 747 | 747 | return $this; |
| 748 | 748 | } |
| 749 | 749 | |
| 750 | - /** |
|
| 751 | - * Attempts to adjust the memory to the required size |
|
| 752 | - * to work with the current image. |
|
| 753 | - * |
|
| 754 | - * @return boolean |
|
| 755 | - */ |
|
| 750 | + /** |
|
| 751 | + * Attempts to adjust the memory to the required size |
|
| 752 | + * to work with the current image. |
|
| 753 | + * |
|
| 754 | + * @return boolean |
|
| 755 | + */ |
|
| 756 | 756 | protected function adjustMemory() : bool |
| 757 | 757 | { |
| 758 | 758 | if(!self::$config['auto-memory-adjustment']) { |
@@ -805,15 +805,15 @@ discard block |
||
| 805 | 805 | return $this->resampleImage($width, $height); |
| 806 | 806 | } |
| 807 | 807 | |
| 808 | - /** |
|
| 809 | - * Creates a new image from the current image, |
|
| 810 | - * resampling it to the new size. |
|
| 811 | - * |
|
| 812 | - * @param int $newWidth |
|
| 813 | - * @param int $newHeight |
|
| 814 | - * @throws ImageHelper_Exception |
|
| 815 | - * @return ImageHelper |
|
| 816 | - */ |
|
| 808 | + /** |
|
| 809 | + * Creates a new image from the current image, |
|
| 810 | + * resampling it to the new size. |
|
| 811 | + * |
|
| 812 | + * @param int $newWidth |
|
| 813 | + * @param int $newHeight |
|
| 814 | + * @throws ImageHelper_Exception |
|
| 815 | + * @return ImageHelper |
|
| 816 | + */ |
|
| 817 | 817 | protected function resampleImage(int $newWidth, int $newHeight) : ImageHelper |
| 818 | 818 | { |
| 819 | 819 | if($this->isVector()) { |
@@ -885,17 +885,17 @@ discard block |
||
| 885 | 885 | return array_unique($types); |
| 886 | 886 | } |
| 887 | 887 | |
| 888 | - /** |
|
| 889 | - * Displays an existing image resource. |
|
| 890 | - * |
|
| 891 | - * @param resource $resource |
|
| 892 | - * @param string $imageType The image format to send, i.e. "jpeg", "png" |
|
| 893 | - * @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 |
|
| 894 | - * |
|
| 895 | - * @throws ImageHelper_Exception |
|
| 896 | - * @see ImageHelper::ERROR_NOT_A_RESOURCE |
|
| 897 | - * @see ImageHelper::ERROR_INVALID_STREAM_IMAGE_TYPE |
|
| 898 | - */ |
|
| 888 | + /** |
|
| 889 | + * Displays an existing image resource. |
|
| 890 | + * |
|
| 891 | + * @param resource $resource |
|
| 892 | + * @param string $imageType The image format to send, i.e. "jpeg", "png" |
|
| 893 | + * @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 |
|
| 894 | + * |
|
| 895 | + * @throws ImageHelper_Exception |
|
| 896 | + * @see ImageHelper::ERROR_NOT_A_RESOURCE |
|
| 897 | + * @see ImageHelper::ERROR_INVALID_STREAM_IMAGE_TYPE |
|
| 898 | + */ |
|
| 899 | 899 | public static function displayImageStream($resource, string $imageType, int $quality=-1) : void |
| 900 | 900 | { |
| 901 | 901 | self::requireResource($resource); |
@@ -979,11 +979,11 @@ discard block |
||
| 979 | 979 | readfile($imageFile); |
| 980 | 980 | } |
| 981 | 981 | |
| 982 | - /** |
|
| 983 | - * Displays the current image. |
|
| 984 | - * |
|
| 985 | - * NOTE: You must call `exit()` manually after this. |
|
| 986 | - */ |
|
| 982 | + /** |
|
| 983 | + * Displays the current image. |
|
| 984 | + * |
|
| 985 | + * NOTE: You must call `exit()` manually after this. |
|
| 986 | + */ |
|
| 987 | 987 | public function display() : void |
| 988 | 988 | { |
| 989 | 989 | self::displayImageStream( |
@@ -1097,14 +1097,14 @@ discard block |
||
| 1097 | 1097 | return $this; |
| 1098 | 1098 | } |
| 1099 | 1099 | |
| 1100 | - /** |
|
| 1101 | - * Requires the subject to be a resource. |
|
| 1102 | - * |
|
| 1103 | - * @param resource|GdImage|mixed $subject |
|
| 1104 | - * |
|
| 1105 | - * @throws ImageHelper_Exception |
|
| 1106 | - * @see ImageHelper::ERROR_NOT_A_RESOURCE |
|
| 1107 | - */ |
|
| 1100 | + /** |
|
| 1101 | + * Requires the subject to be a resource. |
|
| 1102 | + * |
|
| 1103 | + * @param resource|GdImage|mixed $subject |
|
| 1104 | + * |
|
| 1105 | + * @throws ImageHelper_Exception |
|
| 1106 | + * @see ImageHelper::ERROR_NOT_A_RESOURCE |
|
| 1107 | + */ |
|
| 1108 | 1108 | public static function requireResource($subject) : void |
| 1109 | 1109 | { |
| 1110 | 1110 | if(is_resource($subject) && imagesx($subject)) { |
@@ -1125,14 +1125,14 @@ discard block |
||
| 1125 | 1125 | ); |
| 1126 | 1126 | } |
| 1127 | 1127 | |
| 1128 | - /** |
|
| 1129 | - * Creates a new image resource, with transparent background. |
|
| 1130 | - * |
|
| 1131 | - * @param int $width |
|
| 1132 | - * @param int $height |
|
| 1133 | - * @throws ImageHelper_Exception |
|
| 1134 | - * @return resource |
|
| 1135 | - */ |
|
| 1128 | + /** |
|
| 1129 | + * Creates a new image resource, with transparent background. |
|
| 1130 | + * |
|
| 1131 | + * @param int $width |
|
| 1132 | + * @param int $height |
|
| 1133 | + * @throws ImageHelper_Exception |
|
| 1134 | + * @return resource |
|
| 1135 | + */ |
|
| 1136 | 1136 | public function createNewImage(int $width, int $height) |
| 1137 | 1137 | { |
| 1138 | 1138 | $img = imagecreatetruecolor($width, $height); |
@@ -1156,38 +1156,38 @@ discard block |
||
| 1156 | 1156 | * @param int $y |
| 1157 | 1157 | * @return $this |
| 1158 | 1158 | */ |
| 1159 | - public function fillWhite(int $x=0, int $y=0) : self |
|
| 1160 | - { |
|
| 1161 | - $this->addRGBColor('white', 255, 255, 255); |
|
| 1159 | + public function fillWhite(int $x=0, int $y=0) : self |
|
| 1160 | + { |
|
| 1161 | + $this->addRGBColor('white', 255, 255, 255); |
|
| 1162 | 1162 | return $this->fill('white', $x, $y); |
| 1163 | - } |
|
| 1163 | + } |
|
| 1164 | 1164 | |
| 1165 | 1165 | /** |
| 1166 | 1166 | * @return $this |
| 1167 | 1167 | * @throws ImageHelper_Exception |
| 1168 | 1168 | */ |
| 1169 | - public function fillTransparent() : self |
|
| 1170 | - { |
|
| 1169 | + public function fillTransparent() : self |
|
| 1170 | + { |
|
| 1171 | 1171 | $this->enableAlpha(); |
| 1172 | 1172 | |
| 1173 | - self::fillImageTransparent($this->newImage); |
|
| 1173 | + self::fillImageTransparent($this->newImage); |
|
| 1174 | 1174 | |
| 1175 | - return $this; |
|
| 1176 | - } |
|
| 1175 | + return $this; |
|
| 1176 | + } |
|
| 1177 | 1177 | |
| 1178 | 1178 | /** |
| 1179 | 1179 | * @param resource $resource |
| 1180 | 1180 | * @return void |
| 1181 | 1181 | * @throws ImageHelper_Exception |
| 1182 | 1182 | */ |
| 1183 | - public static function fillImageTransparent($resource) : void |
|
| 1184 | - { |
|
| 1185 | - self::requireResource($resource); |
|
| 1183 | + public static function fillImageTransparent($resource) : void |
|
| 1184 | + { |
|
| 1185 | + self::requireResource($resource); |
|
| 1186 | 1186 | |
| 1187 | - $transparent = imagecolorallocatealpha($resource, 89, 14, 207, 127); |
|
| 1188 | - imagecolortransparent ($resource, $transparent); |
|
| 1189 | - imagefill($resource, 0, 0, $transparent); |
|
| 1190 | - } |
|
| 1187 | + $transparent = imagecolorallocatealpha($resource, 89, 14, 207, 127); |
|
| 1188 | + imagecolortransparent ($resource, $transparent); |
|
| 1189 | + imagefill($resource, 0, 0, $transparent); |
|
| 1190 | + } |
|
| 1191 | 1191 | |
| 1192 | 1192 | /** |
| 1193 | 1193 | * @param string $colorName |
@@ -1195,11 +1195,11 @@ discard block |
||
| 1195 | 1195 | * @param int $y |
| 1196 | 1196 | * @return $this |
| 1197 | 1197 | */ |
| 1198 | - public function fill(string $colorName, int $x=0, int $y=0) : self |
|
| 1199 | - { |
|
| 1200 | - imagefill($this->newImage, $x, $y, $this->colors[$colorName]); |
|
| 1201 | - return $this; |
|
| 1202 | - } |
|
| 1198 | + public function fill(string $colorName, int $x=0, int $y=0) : self |
|
| 1199 | + { |
|
| 1200 | + imagefill($this->newImage, $x, $y, $this->colors[$colorName]); |
|
| 1201 | + return $this; |
|
| 1202 | + } |
|
| 1203 | 1203 | |
| 1204 | 1204 | /** |
| 1205 | 1205 | * @param string $name |
@@ -1243,9 +1243,9 @@ discard block |
||
| 1243 | 1243 | return $this; |
| 1244 | 1244 | } |
| 1245 | 1245 | |
| 1246 | - /** |
|
| 1247 | - * @return resource |
|
| 1248 | - */ |
|
| 1246 | + /** |
|
| 1247 | + * @return resource |
|
| 1248 | + */ |
|
| 1249 | 1249 | public function getImage() |
| 1250 | 1250 | { |
| 1251 | 1251 | return $this->newImage; |
@@ -1293,17 +1293,17 @@ discard block |
||
| 1293 | 1293 | * |
| 1294 | 1294 | * @see ImageHelper::ERROR_CANNOT_GET_IMAGE_SIZE |
| 1295 | 1295 | */ |
| 1296 | - public function getSize() : ImageHelper_Size |
|
| 1296 | + public function getSize() : ImageHelper_Size |
|
| 1297 | 1297 | { |
| 1298 | - return self::getImageSize($this->newImage); |
|
| 1298 | + return self::getImageSize($this->newImage); |
|
| 1299 | 1299 | } |
| 1300 | 1300 | |
| 1301 | - /** |
|
| 1302 | - * Sets the TTF font file to use for text operations. |
|
| 1303 | - * |
|
| 1304 | - * @param string $filePath |
|
| 1305 | - * @return $this |
|
| 1306 | - */ |
|
| 1301 | + /** |
|
| 1302 | + * Sets the TTF font file to use for text operations. |
|
| 1303 | + * |
|
| 1304 | + * @param string $filePath |
|
| 1305 | + * @return $this |
|
| 1306 | + */ |
|
| 1307 | 1307 | public function setFontTTF(string $filePath) : self |
| 1308 | 1308 | { |
| 1309 | 1309 | $this->TTFFile = $filePath; |
@@ -1381,7 +1381,7 @@ discard block |
||
| 1381 | 1381 | return; |
| 1382 | 1382 | } |
| 1383 | 1383 | |
| 1384 | - throw new ImageHelper_Exception( |
|
| 1384 | + throw new ImageHelper_Exception( |
|
| 1385 | 1385 | 'No true type font specified', |
| 1386 | 1386 | 'This functionality requires a TTF font file to be specified with the [setFontTTF] method.', |
| 1387 | 1387 | self::ERROR_NO_TRUE_TYPE_FONT_SET |
@@ -1404,37 +1404,37 @@ discard block |
||
| 1404 | 1404 | * @see ImageHelper::ERROR_SVG_SOURCE_VIEWBOX_MISSING |
| 1405 | 1405 | * @see ImageHelper::ERROR_SVG_VIEWBOX_INVALID |
| 1406 | 1406 | */ |
| 1407 | - public static function getImageSize($pathOrResource) : ImageHelper_Size |
|
| 1408 | - { |
|
| 1409 | - if(is_resource($pathOrResource) || $pathOrResource instanceof GdImage) |
|
| 1410 | - { |
|
| 1411 | - return new ImageHelper_Size(array( |
|
| 1412 | - 'width' => imagesx($pathOrResource), |
|
| 1413 | - 'height' => imagesy($pathOrResource), |
|
| 1414 | - 'channels' => 1, |
|
| 1415 | - 'bits' => 8 |
|
| 1416 | - )); |
|
| 1417 | - } |
|
| 1407 | + public static function getImageSize($pathOrResource) : ImageHelper_Size |
|
| 1408 | + { |
|
| 1409 | + if(is_resource($pathOrResource) || $pathOrResource instanceof GdImage) |
|
| 1410 | + { |
|
| 1411 | + return new ImageHelper_Size(array( |
|
| 1412 | + 'width' => imagesx($pathOrResource), |
|
| 1413 | + 'height' => imagesy($pathOrResource), |
|
| 1414 | + 'channels' => 1, |
|
| 1415 | + 'bits' => 8 |
|
| 1416 | + )); |
|
| 1417 | + } |
|
| 1418 | 1418 | |
| 1419 | - $type = self::getFileImageType($pathOrResource); |
|
| 1419 | + $type = self::getFileImageType($pathOrResource); |
|
| 1420 | 1420 | |
| 1421 | 1421 | $sizeMethods = array( |
| 1422 | 1422 | 'svg' => array(self::class, 'getImageSize_svg') |
| 1423 | 1423 | ); |
| 1424 | 1424 | |
| 1425 | - if(isset($sizeMethods[$type])) |
|
| 1426 | - { |
|
| 1427 | - return ClassHelper::requireObjectInstanceOf( |
|
| 1425 | + if(isset($sizeMethods[$type])) |
|
| 1426 | + { |
|
| 1427 | + return ClassHelper::requireObjectInstanceOf( |
|
| 1428 | 1428 | ImageHelper_Size::class, |
| 1429 | 1429 | $sizeMethods[$type]($pathOrResource) |
| 1430 | 1430 | ); |
| 1431 | - } |
|
| 1431 | + } |
|
| 1432 | 1432 | |
| 1433 | - $info = getimagesize($pathOrResource); |
|
| 1433 | + $info = getimagesize($pathOrResource); |
|
| 1434 | 1434 | |
| 1435 | - if($info !== false) { |
|
| 1436 | - return new ImageHelper_Size($info); |
|
| 1437 | - } |
|
| 1435 | + if($info !== false) { |
|
| 1436 | + return new ImageHelper_Size($info); |
|
| 1437 | + } |
|
| 1438 | 1438 | |
| 1439 | 1439 | throw new ImageHelper_Exception( |
| 1440 | 1440 | 'Error opening image file', |
@@ -1444,7 +1444,7 @@ discard block |
||
| 1444 | 1444 | ), |
| 1445 | 1445 | self::ERROR_CANNOT_GET_IMAGE_SIZE |
| 1446 | 1446 | ); |
| 1447 | - } |
|
| 1447 | + } |
|
| 1448 | 1448 | |
| 1449 | 1449 | /** |
| 1450 | 1450 | * @param string $imagePath |
@@ -1454,78 +1454,78 @@ discard block |
||
| 1454 | 1454 | * @throws XMLHelper_Exception |
| 1455 | 1455 | * @throws JsonException |
| 1456 | 1456 | */ |
| 1457 | - protected static function getImageSize_svg(string $imagePath) : ImageHelper_Size |
|
| 1458 | - { |
|
| 1459 | - $xml = XMLHelper::createSimplexml(); |
|
| 1460 | - $xml->loadFile($imagePath); |
|
| 1457 | + protected static function getImageSize_svg(string $imagePath) : ImageHelper_Size |
|
| 1458 | + { |
|
| 1459 | + $xml = XMLHelper::createSimplexml(); |
|
| 1460 | + $xml->loadFile($imagePath); |
|
| 1461 | 1461 | |
| 1462 | - if($xml->hasErrors()) { |
|
| 1463 | - throw new ImageHelper_Exception( |
|
| 1464 | - 'Error opening SVG image', |
|
| 1465 | - sprintf( |
|
| 1466 | - 'The XML content of the image [%s] could not be parsed.', |
|
| 1467 | - $imagePath |
|
| 1462 | + if($xml->hasErrors()) { |
|
| 1463 | + throw new ImageHelper_Exception( |
|
| 1464 | + 'Error opening SVG image', |
|
| 1465 | + sprintf( |
|
| 1466 | + 'The XML content of the image [%s] could not be parsed.', |
|
| 1467 | + $imagePath |
|
| 1468 | 1468 | ), |
| 1469 | - self::ERROR_CANNOT_READ_SVG_IMAGE |
|
| 1469 | + self::ERROR_CANNOT_READ_SVG_IMAGE |
|
| 1470 | 1470 | ); |
| 1471 | - } |
|
| 1471 | + } |
|
| 1472 | 1472 | |
| 1473 | - $data = $xml->toArray(); |
|
| 1474 | - $xml->dispose(); |
|
| 1475 | - unset($xml); |
|
| 1473 | + $data = $xml->toArray(); |
|
| 1474 | + $xml->dispose(); |
|
| 1475 | + unset($xml); |
|
| 1476 | 1476 | |
| 1477 | - if(!isset($data['@attributes']['viewBox'])) { |
|
| 1478 | - throw new ImageHelper_Exception( |
|
| 1479 | - 'SVG Image is corrupted', |
|
| 1480 | - sprintf( |
|
| 1481 | - 'The [viewBox] attribute is missing in the XML of the image at path [%s].', |
|
| 1482 | - $imagePath |
|
| 1477 | + if(!isset($data['@attributes']['viewBox'])) { |
|
| 1478 | + throw new ImageHelper_Exception( |
|
| 1479 | + 'SVG Image is corrupted', |
|
| 1480 | + sprintf( |
|
| 1481 | + 'The [viewBox] attribute is missing in the XML of the image at path [%s].', |
|
| 1482 | + $imagePath |
|
| 1483 | 1483 | ), |
| 1484 | - self::ERROR_SVG_SOURCE_VIEWBOX_MISSING |
|
| 1484 | + self::ERROR_SVG_SOURCE_VIEWBOX_MISSING |
|
| 1485 | 1485 | ); |
| 1486 | - } |
|
| 1486 | + } |
|
| 1487 | 1487 | |
| 1488 | - $svgWidth = parseNumber($data['@attributes']['width'])->getNumber(); |
|
| 1489 | - $svgHeight = parseNumber($data['@attributes']['height'])->getNumber(); |
|
| 1488 | + $svgWidth = parseNumber($data['@attributes']['width'])->getNumber(); |
|
| 1489 | + $svgHeight = parseNumber($data['@attributes']['height'])->getNumber(); |
|
| 1490 | 1490 | |
| 1491 | - $viewBox = str_replace(' ', ',', $data['@attributes']['viewBox']); |
|
| 1492 | - $size = explode(',', $viewBox); |
|
| 1491 | + $viewBox = str_replace(' ', ',', $data['@attributes']['viewBox']); |
|
| 1492 | + $size = explode(',', $viewBox); |
|
| 1493 | 1493 | |
| 1494 | - if(count($size) !== 4) |
|
| 1495 | - { |
|
| 1496 | - throw new ImageHelper_Exception( |
|
| 1497 | - 'SVG image has an invalid viewBox attribute', |
|
| 1498 | - sprintf( |
|
| 1499 | - 'The [viewBox] attribute does not have an expected value: [%s] in path [%s].', |
|
| 1500 | - $viewBox, |
|
| 1501 | - $imagePath |
|
| 1494 | + if(count($size) !== 4) |
|
| 1495 | + { |
|
| 1496 | + throw new ImageHelper_Exception( |
|
| 1497 | + 'SVG image has an invalid viewBox attribute', |
|
| 1498 | + sprintf( |
|
| 1499 | + 'The [viewBox] attribute does not have an expected value: [%s] in path [%s].', |
|
| 1500 | + $viewBox, |
|
| 1501 | + $imagePath |
|
| 1502 | 1502 | ), |
| 1503 | - self::ERROR_SVG_VIEWBOX_INVALID |
|
| 1503 | + self::ERROR_SVG_VIEWBOX_INVALID |
|
| 1504 | 1504 | ); |
| 1505 | - } |
|
| 1505 | + } |
|
| 1506 | 1506 | |
| 1507 | - $boxWidth = (float)$size[2]; |
|
| 1508 | - $boxHeight = (float)$size[3]; |
|
| 1507 | + $boxWidth = (float)$size[2]; |
|
| 1508 | + $boxHeight = (float)$size[3]; |
|
| 1509 | 1509 | |
| 1510 | - // calculate the x and y units of the document: |
|
| 1511 | - // @see http://tutorials.jenkov.com/svg/svg-viewport-view-box.html#viewbox |
|
| 1512 | - // |
|
| 1513 | - // The viewbox combined with the width and height of the svg |
|
| 1514 | - // allow calculating how many pixels are in one unit of the |
|
| 1515 | - // width and height of the document. |
|
| 1510 | + // calculate the x and y units of the document: |
|
| 1511 | + // @see http://tutorials.jenkov.com/svg/svg-viewport-view-box.html#viewbox |
|
| 1516 | 1512 | // |
| 1517 | - $xUnits = $svgWidth / $boxWidth; |
|
| 1518 | - $yUnits = $svgHeight / $boxHeight; |
|
| 1513 | + // The viewbox combined with the width and height of the svg |
|
| 1514 | + // allow calculating how many pixels are in one unit of the |
|
| 1515 | + // width and height of the document. |
|
| 1516 | + // |
|
| 1517 | + $xUnits = $svgWidth / $boxWidth; |
|
| 1518 | + $yUnits = $svgHeight / $boxHeight; |
|
| 1519 | 1519 | |
| 1520 | - $pxWidth = $xUnits * $svgWidth; |
|
| 1521 | - $pxHeight = $yUnits * $svgHeight; |
|
| 1520 | + $pxWidth = $xUnits * $svgWidth; |
|
| 1521 | + $pxHeight = $yUnits * $svgHeight; |
|
| 1522 | 1522 | |
| 1523 | - return new ImageHelper_Size(array( |
|
| 1523 | + return new ImageHelper_Size(array( |
|
| 1524 | 1524 | (int)$pxWidth, |
| 1525 | 1525 | (int)$pxHeight, |
| 1526 | - 'bits' => 8 |
|
| 1527 | - )); |
|
| 1528 | - } |
|
| 1526 | + 'bits' => 8 |
|
| 1527 | + )); |
|
| 1528 | + } |
|
| 1529 | 1529 | |
| 1530 | 1530 | /** |
| 1531 | 1531 | * Crops the image to the specified width and height, optionally |
@@ -1584,26 +1584,26 @@ discard block |
||
| 1584 | 1584 | return $image->getColorAt(0, 0); |
| 1585 | 1585 | } |
| 1586 | 1586 | |
| 1587 | - /** |
|
| 1588 | - * Calculates the image's average color value, and |
|
| 1589 | - * returns an associative array with red, green, |
|
| 1590 | - * blue and alpha keys. |
|
| 1591 | - * |
|
| 1592 | - * @throws ImageHelper_Exception |
|
| 1593 | - * @return RGBAColor |
|
| 1594 | - */ |
|
| 1587 | + /** |
|
| 1588 | + * Calculates the image's average color value, and |
|
| 1589 | + * returns an associative array with red, green, |
|
| 1590 | + * blue and alpha keys. |
|
| 1591 | + * |
|
| 1592 | + * @throws ImageHelper_Exception |
|
| 1593 | + * @return RGBAColor |
|
| 1594 | + */ |
|
| 1595 | 1595 | public function calcAverageColorRGB() : RGBAColor |
| 1596 | 1596 | { |
| 1597 | - return $this->calcAverageColor(); |
|
| 1597 | + return $this->calcAverageColor(); |
|
| 1598 | 1598 | } |
| 1599 | 1599 | |
| 1600 | - /** |
|
| 1601 | - * Calculates the image's average color value, and |
|
| 1602 | - * returns a hex color string (without the #). |
|
| 1603 | - * |
|
| 1604 | - * @throws ImageHelper_Exception |
|
| 1605 | - * @return string |
|
| 1606 | - */ |
|
| 1600 | + /** |
|
| 1601 | + * Calculates the image's average color value, and |
|
| 1602 | + * returns a hex color string (without the #). |
|
| 1603 | + * |
|
| 1604 | + * @throws ImageHelper_Exception |
|
| 1605 | + * @return string |
|
| 1606 | + */ |
|
| 1607 | 1607 | public function calcAverageColorHex() : string |
| 1608 | 1608 | { |
| 1609 | 1609 | return $this->calcAverageColor()->toHEX(); |
@@ -1653,15 +1653,15 @@ discard block |
||
| 1653 | 1653 | return $this->calcAverageColorRGB()->getBrightness(); |
| 1654 | 1654 | } |
| 1655 | 1655 | |
| 1656 | - /** |
|
| 1657 | - * Retrieves a md5 hash of the source image file. |
|
| 1658 | - * |
|
| 1659 | - * NOTE: Only works when the helper has been created |
|
| 1660 | - * from a file. Otherwise, an exception is thrown. |
|
| 1661 | - * |
|
| 1662 | - * @return string |
|
| 1663 | - * @throws ImageHelper_Exception|OutputBuffering_Exception |
|
| 1664 | - */ |
|
| 1656 | + /** |
|
| 1657 | + * Retrieves a md5 hash of the source image file. |
|
| 1658 | + * |
|
| 1659 | + * NOTE: Only works when the helper has been created |
|
| 1660 | + * from a file. Otherwise, an exception is thrown. |
|
| 1661 | + * |
|
| 1662 | + * @return string |
|
| 1663 | + * @throws ImageHelper_Exception|OutputBuffering_Exception |
|
| 1664 | + */ |
|
| 1665 | 1665 | public function getHash() : string |
| 1666 | 1666 | { |
| 1667 | 1667 | if($this->newImage === null) |
@@ -120,10 +120,10 @@ discard block |
||
| 120 | 120 | * |
| 121 | 121 | * @see ImageHelper::ERROR_GD_LIBRARY_NOT_INSTALLED |
| 122 | 122 | */ |
| 123 | - public function __construct(?string $sourceFile=null, $resource=null, ?string $type=null) |
|
| 123 | + public function __construct(?string $sourceFile = null, $resource = null, ?string $type = null) |
|
| 124 | 124 | { |
| 125 | 125 | // ensure that the GD library is installed |
| 126 | - if(!function_exists('imagecreate')) |
|
| 126 | + if (!function_exists('imagecreate')) |
|
| 127 | 127 | { |
| 128 | 128 | throw new ImageHelper_Exception( |
| 129 | 129 | 'The PHP GD extension is not installed or not enabled.', |
@@ -132,7 +132,7 @@ discard block |
||
| 132 | 132 | ); |
| 133 | 133 | } |
| 134 | 134 | |
| 135 | - if(is_resource($resource) || $resource instanceof GdImage) |
|
| 135 | + if (is_resource($resource) || $resource instanceof GdImage) |
|
| 136 | 136 | { |
| 137 | 137 | $this->sourceImage = $resource; |
| 138 | 138 | $this->type = $type; |
@@ -156,7 +156,7 @@ discard block |
||
| 156 | 156 | if ($type === null) { |
| 157 | 157 | throw new ImageHelper_Exception( |
| 158 | 158 | 'Error opening image', |
| 159 | - 'Not a valid supported image type for image ' . $this->file, |
|
| 159 | + 'Not a valid supported image type for image '.$this->file, |
|
| 160 | 160 | self::ERROR_UNSUPPORTED_IMAGE_TYPE |
| 161 | 161 | ); |
| 162 | 162 | } |
@@ -164,14 +164,14 @@ discard block |
||
| 164 | 164 | $this->type = $type; |
| 165 | 165 | $this->info = self::getImageSize($this->file); |
| 166 | 166 | |
| 167 | - if(!$this->isVector()) |
|
| 167 | + if (!$this->isVector()) |
|
| 168 | 168 | { |
| 169 | - $method = 'imagecreatefrom' . $this->type; |
|
| 169 | + $method = 'imagecreatefrom'.$this->type; |
|
| 170 | 170 | $this->sourceImage = $method($this->file); |
| 171 | 171 | if (!$this->sourceImage) { |
| 172 | 172 | throw new ImageHelper_Exception( |
| 173 | 173 | 'Error creating new image', |
| 174 | - $method . ' failed', |
|
| 174 | + $method.' failed', |
|
| 175 | 175 | self::ERROR_FAILED_TO_CREATE_NEW_IMAGE |
| 176 | 176 | ); |
| 177 | 177 | } |
@@ -183,7 +183,7 @@ discard block |
||
| 183 | 183 | $this->width = $this->info->getWidth(); |
| 184 | 184 | $this->height = $this->info->getHeight(); |
| 185 | 185 | |
| 186 | - if(!$this->isVector()) { |
|
| 186 | + if (!$this->isVector()) { |
|
| 187 | 187 | $this->setNewImage($this->duplicateImage($this->sourceImage)); |
| 188 | 188 | } |
| 189 | 189 | } |
@@ -199,10 +199,10 @@ discard block |
||
| 199 | 199 | * |
| 200 | 200 | * @see ImageHelper::ERROR_CANNOT_CREATE_IMAGE_OBJECT |
| 201 | 201 | */ |
| 202 | - public static function createNew(int $width, int $height, string $type='png') : self |
|
| 202 | + public static function createNew(int $width, int $height, string $type = 'png') : self |
|
| 203 | 203 | { |
| 204 | 204 | $img = imagecreatetruecolor($width, $height); |
| 205 | - if($img !== false) { |
|
| 205 | + if ($img !== false) { |
|
| 206 | 206 | return self::createFromResource($img, $type); |
| 207 | 207 | } |
| 208 | 208 | |
@@ -226,7 +226,7 @@ discard block |
||
| 226 | 226 | * @return ImageHelper |
| 227 | 227 | * @throws ImageHelper_Exception |
| 228 | 228 | */ |
| 229 | - public static function createFromResource($resource, ?string $type=null) : ImageHelper |
|
| 229 | + public static function createFromResource($resource, ?string $type = null) : ImageHelper |
|
| 230 | 230 | { |
| 231 | 231 | self::requireResource($resource); |
| 232 | 232 | |
@@ -262,7 +262,7 @@ discard block |
||
| 262 | 262 | */ |
| 263 | 263 | public static function setConfig(string $name, $value) : void |
| 264 | 264 | { |
| 265 | - if(isset(self::$config[$name])) { |
|
| 265 | + if (isset(self::$config[$name])) { |
|
| 266 | 266 | self::$config[$name] = $value; |
| 267 | 267 | } |
| 268 | 268 | } |
@@ -274,7 +274,7 @@ discard block |
||
| 274 | 274 | * @param bool $enabled |
| 275 | 275 | * @return void |
| 276 | 276 | */ |
| 277 | - public static function setAutoMemoryAdjustment(bool $enabled=true) : void |
|
| 277 | + public static function setAutoMemoryAdjustment(bool $enabled = true) : void |
|
| 278 | 278 | { |
| 279 | 279 | self::setConfig('auto-memory-adjustment', $enabled); |
| 280 | 280 | } |
@@ -314,7 +314,7 @@ discard block |
||
| 314 | 314 | */ |
| 315 | 315 | public function enableAlpha() : self |
| 316 | 316 | { |
| 317 | - if(!$this->alpha) |
|
| 317 | + if (!$this->alpha) |
|
| 318 | 318 | { |
| 319 | 319 | self::addAlphaSupport($this->newImage, false); |
| 320 | 320 | $this->alpha = true; |
@@ -354,9 +354,9 @@ discard block |
||
| 354 | 354 | * @param int|float $percent |
| 355 | 355 | * @return $this |
| 356 | 356 | */ |
| 357 | - public function sharpen($percent=0) : self |
|
| 357 | + public function sharpen($percent = 0) : self |
|
| 358 | 358 | { |
| 359 | - if($percent <= 0) { |
|
| 359 | + if ($percent <= 0) { |
|
| 360 | 360 | return $this; |
| 361 | 361 | } |
| 362 | 362 | |
@@ -369,9 +369,9 @@ discard block |
||
| 369 | 369 | * @param int|float $percent |
| 370 | 370 | * @return $this |
| 371 | 371 | */ |
| 372 | - public function blur($percent=0) : self |
|
| 372 | + public function blur($percent = 0) : self |
|
| 373 | 373 | { |
| 374 | - if($percent <= 0) { |
|
| 374 | + if ($percent <= 0) { |
|
| 375 | 375 | return $this; |
| 376 | 376 | } |
| 377 | 377 | |
@@ -388,12 +388,12 @@ discard block |
||
| 388 | 388 | { |
| 389 | 389 | // get a value that's equal to 64 - abs( factor ) |
| 390 | 390 | // ( using min/max to limit the factor to 0 - 64 to not get out of range values ) |
| 391 | - $val1Adjustment = 64 - min( 64, max( 0, abs( $factor ) ) ); |
|
| 391 | + $val1Adjustment = 64 - min(64, max(0, abs($factor))); |
|
| 392 | 392 | |
| 393 | 393 | // the base factor for the "current" pixel depends on if we are blurring or sharpening. |
| 394 | 394 | // If we are blurring use 1, if sharpening use 9. |
| 395 | 395 | $val1Base = 9; |
| 396 | - if( abs( $factor ) !== $factor ) { |
|
| 396 | + if (abs($factor) !== $factor) { |
|
| 397 | 397 | $val1Base = 1; |
| 398 | 398 | } |
| 399 | 399 | |
@@ -406,24 +406,24 @@ discard block |
||
| 406 | 406 | |
| 407 | 407 | // the value for the surrounding pixels is either positive or negative depending on if we are blurring or sharpening. |
| 408 | 408 | $val2 = -1; |
| 409 | - if( abs( $factor ) !== $factor ) { |
|
| 409 | + if (abs($factor) !== $factor) { |
|
| 410 | 410 | $val2 = 1; |
| 411 | 411 | } |
| 412 | 412 | |
| 413 | 413 | // setup matrix .. |
| 414 | 414 | $matrix = array( |
| 415 | - array( $val2, $val2, $val2 ), |
|
| 416 | - array( $val2, $val1, $val2 ), |
|
| 417 | - array( $val2, $val2, $val2 ) |
|
| 415 | + array($val2, $val2, $val2), |
|
| 416 | + array($val2, $val1, $val2), |
|
| 417 | + array($val2, $val2, $val2) |
|
| 418 | 418 | ); |
| 419 | 419 | |
| 420 | 420 | // calculate the correct divisor |
| 421 | 421 | // actual divisor is equal to "$divisor = $val1 + $val2 * 8;" |
| 422 | 422 | // but the following line is more generic |
| 423 | - $divisor = array_sum( array_map( 'array_sum', $matrix ) ); |
|
| 423 | + $divisor = array_sum(array_map('array_sum', $matrix)); |
|
| 424 | 424 | |
| 425 | 425 | // apply the matrix |
| 426 | - imageconvolution( $this->newImage, $matrix, $divisor, 0 ); |
|
| 426 | + imageconvolution($this->newImage, $matrix, $divisor, 0); |
|
| 427 | 427 | |
| 428 | 428 | return $this; |
| 429 | 429 | } |
@@ -552,7 +552,7 @@ discard block |
||
| 552 | 552 | */ |
| 553 | 553 | public function resample(?int $width = null, ?int $height = null) : ImageHelper |
| 554 | 554 | { |
| 555 | - if($this->isVector()) { |
|
| 555 | + if ($this->isVector()) { |
|
| 556 | 556 | return $this; |
| 557 | 557 | } |
| 558 | 558 | |
@@ -573,7 +573,7 @@ discard block |
||
| 573 | 573 | |
| 574 | 574 | public function resampleAndCrop(int $width, int $height) : ImageHelper |
| 575 | 575 | { |
| 576 | - if($this->isVector()) { |
|
| 576 | + if ($this->isVector()) { |
|
| 577 | 577 | return $this; |
| 578 | 578 | } |
| 579 | 579 | |
@@ -619,14 +619,14 @@ discard block |
||
| 619 | 619 | * @param bool $fill Whether to fill the whole canvas with the transparency |
| 620 | 620 | * @throws ImageHelper_Exception |
| 621 | 621 | */ |
| 622 | - public static function addAlphaSupport($canvas, bool $fill=true) : void |
|
| 622 | + public static function addAlphaSupport($canvas, bool $fill = true) : void |
|
| 623 | 623 | { |
| 624 | 624 | self::requireResource($canvas); |
| 625 | 625 | |
| 626 | - imagealphablending($canvas,true); |
|
| 626 | + imagealphablending($canvas, true); |
|
| 627 | 627 | imagesavealpha($canvas, true); |
| 628 | 628 | |
| 629 | - if($fill) { |
|
| 629 | + if ($fill) { |
|
| 630 | 630 | self::fillImageTransparent($canvas); |
| 631 | 631 | } |
| 632 | 632 | } |
@@ -642,13 +642,13 @@ discard block |
||
| 642 | 642 | * @return $this |
| 643 | 643 | * @throws ImageHelper_Exception |
| 644 | 644 | */ |
| 645 | - public function save(string $targetFile, bool $dispose=true) : self |
|
| 645 | + public function save(string $targetFile, bool $dispose = true) : self |
|
| 646 | 646 | { |
| 647 | - if($this->isVector()) { |
|
| 647 | + if ($this->isVector()) { |
|
| 648 | 648 | return $this; |
| 649 | 649 | } |
| 650 | 650 | |
| 651 | - if(!is_resource($this->newImage)) { |
|
| 651 | + if (!is_resource($this->newImage)) { |
|
| 652 | 652 | throw new ImageHelper_Exception( |
| 653 | 653 | 'Error creating new image', |
| 654 | 654 | 'Cannot save an image, no valid image resource was created. You have to call one of the resample methods to create a new image.', |
@@ -660,7 +660,7 @@ discard block |
||
| 660 | 660 | unlink($targetFile); |
| 661 | 661 | } |
| 662 | 662 | |
| 663 | - $method = 'image' . $this->type; |
|
| 663 | + $method = 'image'.$this->type; |
|
| 664 | 664 | if (!$method($this->newImage, $targetFile, $this->resolveQuality())) { |
| 665 | 665 | throw new ImageHelper_Exception( |
| 666 | 666 | 'Error creating new image', |
@@ -681,7 +681,7 @@ discard block |
||
| 681 | 681 | ); |
| 682 | 682 | } |
| 683 | 683 | |
| 684 | - if($dispose) { |
|
| 684 | + if ($dispose) { |
|
| 685 | 685 | $this->dispose(); |
| 686 | 686 | } |
| 687 | 687 | |
@@ -693,11 +693,11 @@ discard block |
||
| 693 | 693 | */ |
| 694 | 694 | public function dispose() : self |
| 695 | 695 | { |
| 696 | - if(is_resource($this->sourceImage)) { |
|
| 696 | + if (is_resource($this->sourceImage)) { |
|
| 697 | 697 | imagedestroy($this->sourceImage); |
| 698 | 698 | } |
| 699 | 699 | |
| 700 | - if(is_resource($this->newImage)) { |
|
| 700 | + if (is_resource($this->newImage)) { |
|
| 701 | 701 | imagedestroy($this->newImage); |
| 702 | 702 | } |
| 703 | 703 | |
@@ -755,7 +755,7 @@ discard block |
||
| 755 | 755 | */ |
| 756 | 756 | protected function adjustMemory() : bool |
| 757 | 757 | { |
| 758 | - if(!self::$config['auto-memory-adjustment']) { |
|
| 758 | + if (!self::$config['auto-memory-adjustment']) { |
|
| 759 | 759 | return true; |
| 760 | 760 | } |
| 761 | 761 | |
@@ -784,7 +784,7 @@ discard block |
||
| 784 | 784 | if (function_exists('memory_get_usage') && memory_get_usage() + $memoryNeeded > $memoryLimit) { |
| 785 | 785 | $newLimit = ($memoryLimit + (memory_get_usage() + $memoryNeeded)) / $MB; |
| 786 | 786 | $newLimit = ceil($newLimit); |
| 787 | - ini_set('memory_limit', $newLimit . 'M'); |
|
| 787 | + ini_set('memory_limit', $newLimit.'M'); |
|
| 788 | 788 | |
| 789 | 789 | return true; |
| 790 | 790 | } |
@@ -816,16 +816,16 @@ discard block |
||
| 816 | 816 | */ |
| 817 | 817 | protected function resampleImage(int $newWidth, int $newHeight) : ImageHelper |
| 818 | 818 | { |
| 819 | - if($this->isVector()) { |
|
| 819 | + if ($this->isVector()) { |
|
| 820 | 820 | return $this; |
| 821 | 821 | } |
| 822 | 822 | |
| 823 | - if($this->newWidth===$newWidth && $this->newHeight===$newHeight) { |
|
| 823 | + if ($this->newWidth === $newWidth && $this->newHeight === $newHeight) { |
|
| 824 | 824 | return $this; |
| 825 | 825 | } |
| 826 | 826 | |
| 827 | - if($newWidth < 1) { $newWidth = 1; } |
|
| 828 | - if($newHeight < 1) { $newHeight = 1; } |
|
| 827 | + if ($newWidth < 1) { $newWidth = 1; } |
|
| 828 | + if ($newHeight < 1) { $newHeight = 1; } |
|
| 829 | 829 | |
| 830 | 830 | $this->adjustMemory(); |
| 831 | 831 | |
@@ -856,7 +856,7 @@ discard block |
||
| 856 | 856 | */ |
| 857 | 857 | public static function getFileImageType($pathOrResource) : ?string |
| 858 | 858 | { |
| 859 | - if(!is_string($pathOrResource)) { |
|
| 859 | + if (!is_string($pathOrResource)) { |
|
| 860 | 860 | return 'png'; |
| 861 | 861 | } |
| 862 | 862 | |
@@ -896,15 +896,15 @@ discard block |
||
| 896 | 896 | * @see ImageHelper::ERROR_NOT_A_RESOURCE |
| 897 | 897 | * @see ImageHelper::ERROR_INVALID_STREAM_IMAGE_TYPE |
| 898 | 898 | */ |
| 899 | - public static function displayImageStream($resource, string $imageType, int $quality=-1) : void |
|
| 899 | + public static function displayImageStream($resource, string $imageType, int $quality = -1) : void |
|
| 900 | 900 | { |
| 901 | 901 | self::requireResource($resource); |
| 902 | 902 | |
| 903 | 903 | $imageType = self::requireValidStreamType($imageType); |
| 904 | 904 | |
| 905 | - header('Content-type:image/' . $imageType); |
|
| 905 | + header('Content-type:image/'.$imageType); |
|
| 906 | 906 | |
| 907 | - $function = 'image' . $imageType; |
|
| 907 | + $function = 'image'.$imageType; |
|
| 908 | 908 | |
| 909 | 909 | $function($resource, null, $quality); |
| 910 | 910 | } |
@@ -921,7 +921,7 @@ discard block |
||
| 921 | 921 | { |
| 922 | 922 | $imageType = strtolower($imageType); |
| 923 | 923 | |
| 924 | - if(in_array($imageType, self::$streamTypes)) |
|
| 924 | + if (in_array($imageType, self::$streamTypes)) |
|
| 925 | 925 | { |
| 926 | 926 | return $imageType; |
| 927 | 927 | } |
@@ -948,7 +948,7 @@ discard block |
||
| 948 | 948 | if (headers_sent($file, $line)) { |
| 949 | 949 | throw new ImageHelper_Exception( |
| 950 | 950 | 'Error displaying image', |
| 951 | - 'Headers have already been sent: in file ' . $file . ':' . $line, |
|
| 951 | + 'Headers have already been sent: in file '.$file.':'.$line, |
|
| 952 | 952 | self::ERROR_HEADERS_ALREADY_SENT |
| 953 | 953 | ); |
| 954 | 954 | } |
@@ -965,16 +965,16 @@ discard block |
||
| 965 | 965 | } |
| 966 | 966 | |
| 967 | 967 | $format = self::getFileImageType($imageFile); |
| 968 | - if($format === 'svg') { |
|
| 968 | + if ($format === 'svg') { |
|
| 969 | 969 | $format = 'svg+xml'; |
| 970 | 970 | } |
| 971 | 971 | |
| 972 | - $contentType = 'image/' . $format; |
|
| 972 | + $contentType = 'image/'.$format; |
|
| 973 | 973 | |
| 974 | 974 | header('Content-Type: '.$contentType); |
| 975 | - header("Last-Modified: " . gmdate("D, d M Y H:i:s", filemtime($imageFile)) . " GMT"); |
|
| 975 | + header("Last-Modified: ".gmdate("D, d M Y H:i:s", filemtime($imageFile))." GMT"); |
|
| 976 | 976 | header('Cache-Control: public'); |
| 977 | - header('Content-Length: ' . filesize($imageFile)); |
|
| 977 | + header('Content-Length: '.filesize($imageFile)); |
|
| 978 | 978 | |
| 979 | 979 | readfile($imageFile); |
| 980 | 980 | } |
@@ -1005,7 +1005,7 @@ discard block |
||
| 1005 | 1005 | * @see ImageHelper::ERROR_NOT_A_RESOURCE |
| 1006 | 1006 | * @see ImageHelper::ERROR_CANNOT_CREATE_IMAGE_CANVAS |
| 1007 | 1007 | */ |
| 1008 | - public function trim(?RGBAColor $color=null) : ImageHelper |
|
| 1008 | + public function trim(?RGBAColor $color = null) : ImageHelper |
|
| 1009 | 1009 | { |
| 1010 | 1010 | return $this->trimImage($this->newImage, $color); |
| 1011 | 1011 | } |
@@ -1054,9 +1054,9 @@ discard block |
||
| 1054 | 1054 | * |
| 1055 | 1055 | * @throws ImageHelper_Exception |
| 1056 | 1056 | */ |
| 1057 | - protected function trimImage($img, ?RGBAColor $trimColor=null) : ImageHelper |
|
| 1057 | + protected function trimImage($img, ?RGBAColor $trimColor = null) : ImageHelper |
|
| 1058 | 1058 | { |
| 1059 | - if($this->isVector()) { |
|
| 1059 | + if ($this->isVector()) { |
|
| 1060 | 1060 | return $this; |
| 1061 | 1061 | } |
| 1062 | 1062 | |
@@ -1065,7 +1065,7 @@ discard block |
||
| 1065 | 1065 | $trimmer = new ImageTrimmer($this, $img, $trimColor); |
| 1066 | 1066 | $new = $trimmer->trim(); |
| 1067 | 1067 | |
| 1068 | - if($new === null) { |
|
| 1068 | + if ($new === null) { |
|
| 1069 | 1069 | return $this; |
| 1070 | 1070 | } |
| 1071 | 1071 | |
@@ -1092,7 +1092,7 @@ discard block |
||
| 1092 | 1092 | |
| 1093 | 1093 | $this->newImage = $image; |
| 1094 | 1094 | $this->newWidth = imagesx($image); |
| 1095 | - $this->newHeight= imagesy($image); |
|
| 1095 | + $this->newHeight = imagesy($image); |
|
| 1096 | 1096 | |
| 1097 | 1097 | return $this; |
| 1098 | 1098 | } |
@@ -1107,11 +1107,11 @@ discard block |
||
| 1107 | 1107 | */ |
| 1108 | 1108 | public static function requireResource($subject) : void |
| 1109 | 1109 | { |
| 1110 | - if(is_resource($subject) && imagesx($subject)) { |
|
| 1110 | + if (is_resource($subject) && imagesx($subject)) { |
|
| 1111 | 1111 | return; |
| 1112 | 1112 | } |
| 1113 | 1113 | |
| 1114 | - if($subject instanceof GdImage) { |
|
| 1114 | + if ($subject instanceof GdImage) { |
|
| 1115 | 1115 | return; |
| 1116 | 1116 | } |
| 1117 | 1117 | |
@@ -1137,7 +1137,7 @@ discard block |
||
| 1137 | 1137 | { |
| 1138 | 1138 | $img = imagecreatetruecolor($width, $height); |
| 1139 | 1139 | |
| 1140 | - if($img === false) |
|
| 1140 | + if ($img === false) |
|
| 1141 | 1141 | { |
| 1142 | 1142 | throw new ImageHelper_Exception( |
| 1143 | 1143 | 'Error creating new image', |
@@ -1156,7 +1156,7 @@ discard block |
||
| 1156 | 1156 | * @param int $y |
| 1157 | 1157 | * @return $this |
| 1158 | 1158 | */ |
| 1159 | - public function fillWhite(int $x=0, int $y=0) : self |
|
| 1159 | + public function fillWhite(int $x = 0, int $y = 0) : self |
|
| 1160 | 1160 | { |
| 1161 | 1161 | $this->addRGBColor('white', 255, 255, 255); |
| 1162 | 1162 | return $this->fill('white', $x, $y); |
@@ -1185,7 +1185,7 @@ discard block |
||
| 1185 | 1185 | self::requireResource($resource); |
| 1186 | 1186 | |
| 1187 | 1187 | $transparent = imagecolorallocatealpha($resource, 89, 14, 207, 127); |
| 1188 | - imagecolortransparent ($resource, $transparent); |
|
| 1188 | + imagecolortransparent($resource, $transparent); |
|
| 1189 | 1189 | imagefill($resource, 0, 0, $transparent); |
| 1190 | 1190 | } |
| 1191 | 1191 | |
@@ -1195,7 +1195,7 @@ discard block |
||
| 1195 | 1195 | * @param int $y |
| 1196 | 1196 | * @return $this |
| 1197 | 1197 | */ |
| 1198 | - public function fill(string $colorName, int $x=0, int $y=0) : self |
|
| 1198 | + public function fill(string $colorName, int $x = 0, int $y = 0) : self |
|
| 1199 | 1199 | { |
| 1200 | 1200 | imagefill($this->newImage, $x, $y, $this->colors[$colorName]); |
| 1201 | 1201 | return $this; |
@@ -1223,7 +1223,7 @@ discard block |
||
| 1223 | 1223 | * @param int|float $angle |
| 1224 | 1224 | * @return $this |
| 1225 | 1225 | */ |
| 1226 | - public function textTTF(string $text, $size, string $colorName, int $x=0, int $y=0, $angle=0) : self |
|
| 1226 | + public function textTTF(string $text, $size, string $colorName, int $x = 0, int $y = 0, $angle = 0) : self |
|
| 1227 | 1227 | { |
| 1228 | 1228 | imagealphablending($this->newImage, true); |
| 1229 | 1229 | |
@@ -1260,11 +1260,11 @@ discard block |
||
| 1260 | 1260 | * @return $this |
| 1261 | 1261 | * @throws ImageHelper_Exception |
| 1262 | 1262 | */ |
| 1263 | - public function paste(ImageHelper $target, int $xpos=0, int $ypos=0, int $sourceX=0, int $sourceY=0) : self |
|
| 1263 | + public function paste(ImageHelper $target, int $xpos = 0, int $ypos = 0, int $sourceX = 0, int $sourceY = 0) : self |
|
| 1264 | 1264 | { |
| 1265 | 1265 | $img = $target->getImage(); |
| 1266 | 1266 | |
| 1267 | - if($target->isAlpha()) { |
|
| 1267 | + if ($target->isAlpha()) { |
|
| 1268 | 1268 | $this->enableAlpha(); |
| 1269 | 1269 | } |
| 1270 | 1270 | |
@@ -1326,10 +1326,10 @@ discard block |
||
| 1326 | 1326 | */ |
| 1327 | 1327 | $sizes = array(); |
| 1328 | 1328 | |
| 1329 | - for($i=1; $i<=1000; $i += 0.1) { |
|
| 1329 | + for ($i = 1; $i <= 1000; $i += 0.1) { |
|
| 1330 | 1330 | $size = $this->calcTextSize($text, $i); |
| 1331 | 1331 | $sizes[] = $size; |
| 1332 | - if($size->getWidth() >= $matchWidth) { |
|
| 1332 | + if ($size->getWidth() >= $matchWidth) { |
|
| 1333 | 1333 | break; |
| 1334 | 1334 | } |
| 1335 | 1335 | } |
@@ -1341,7 +1341,7 @@ discard block |
||
| 1341 | 1341 | $diffLast = $last->getWidth() - $matchWidth; |
| 1342 | 1342 | $diffPrev = $matchWidth - $prev->getWidth(); |
| 1343 | 1343 | |
| 1344 | - if($diffLast <= $diffPrev) { |
|
| 1344 | + if ($diffLast <= $diffPrev) { |
|
| 1345 | 1345 | return $last; |
| 1346 | 1346 | } |
| 1347 | 1347 | |
@@ -1370,14 +1370,14 @@ discard block |
||
| 1370 | 1370 | 'bottom_left_y' => $box[1], |
| 1371 | 1371 | 'bottom_right_x' => $box[2], |
| 1372 | 1372 | 'bottom_right_y' => $box[3], |
| 1373 | - 'width' => $box[4]-$box[0], |
|
| 1374 | - 'height' => $box[1]-$box[7] |
|
| 1373 | + 'width' => $box[4] - $box[0], |
|
| 1374 | + 'height' => $box[1] - $box[7] |
|
| 1375 | 1375 | )); |
| 1376 | 1376 | } |
| 1377 | 1377 | |
| 1378 | 1378 | protected function requireTTFFont() : void |
| 1379 | 1379 | { |
| 1380 | - if(!empty($this->TTFFile)) { |
|
| 1380 | + if (!empty($this->TTFFile)) { |
|
| 1381 | 1381 | return; |
| 1382 | 1382 | } |
| 1383 | 1383 | |
@@ -1406,7 +1406,7 @@ discard block |
||
| 1406 | 1406 | */ |
| 1407 | 1407 | public static function getImageSize($pathOrResource) : ImageHelper_Size |
| 1408 | 1408 | { |
| 1409 | - if(is_resource($pathOrResource) || $pathOrResource instanceof GdImage) |
|
| 1409 | + if (is_resource($pathOrResource) || $pathOrResource instanceof GdImage) |
|
| 1410 | 1410 | { |
| 1411 | 1411 | return new ImageHelper_Size(array( |
| 1412 | 1412 | 'width' => imagesx($pathOrResource), |
@@ -1422,7 +1422,7 @@ discard block |
||
| 1422 | 1422 | 'svg' => array(self::class, 'getImageSize_svg') |
| 1423 | 1423 | ); |
| 1424 | 1424 | |
| 1425 | - if(isset($sizeMethods[$type])) |
|
| 1425 | + if (isset($sizeMethods[$type])) |
|
| 1426 | 1426 | { |
| 1427 | 1427 | return ClassHelper::requireObjectInstanceOf( |
| 1428 | 1428 | ImageHelper_Size::class, |
@@ -1432,7 +1432,7 @@ discard block |
||
| 1432 | 1432 | |
| 1433 | 1433 | $info = getimagesize($pathOrResource); |
| 1434 | 1434 | |
| 1435 | - if($info !== false) { |
|
| 1435 | + if ($info !== false) { |
|
| 1436 | 1436 | return new ImageHelper_Size($info); |
| 1437 | 1437 | } |
| 1438 | 1438 | |
@@ -1459,7 +1459,7 @@ discard block |
||
| 1459 | 1459 | $xml = XMLHelper::createSimplexml(); |
| 1460 | 1460 | $xml->loadFile($imagePath); |
| 1461 | 1461 | |
| 1462 | - if($xml->hasErrors()) { |
|
| 1462 | + if ($xml->hasErrors()) { |
|
| 1463 | 1463 | throw new ImageHelper_Exception( |
| 1464 | 1464 | 'Error opening SVG image', |
| 1465 | 1465 | sprintf( |
@@ -1474,7 +1474,7 @@ discard block |
||
| 1474 | 1474 | $xml->dispose(); |
| 1475 | 1475 | unset($xml); |
| 1476 | 1476 | |
| 1477 | - if(!isset($data['@attributes']['viewBox'])) { |
|
| 1477 | + if (!isset($data['@attributes']['viewBox'])) { |
|
| 1478 | 1478 | throw new ImageHelper_Exception( |
| 1479 | 1479 | 'SVG Image is corrupted', |
| 1480 | 1480 | sprintf( |
@@ -1491,7 +1491,7 @@ discard block |
||
| 1491 | 1491 | $viewBox = str_replace(' ', ',', $data['@attributes']['viewBox']); |
| 1492 | 1492 | $size = explode(',', $viewBox); |
| 1493 | 1493 | |
| 1494 | - if(count($size) !== 4) |
|
| 1494 | + if (count($size) !== 4) |
|
| 1495 | 1495 | { |
| 1496 | 1496 | throw new ImageHelper_Exception( |
| 1497 | 1497 | 'SVG image has an invalid viewBox attribute', |
@@ -1538,7 +1538,7 @@ discard block |
||
| 1538 | 1538 | * @return $this |
| 1539 | 1539 | * @throws ImageHelper_Exception |
| 1540 | 1540 | */ |
| 1541 | - public function crop(int $width, int $height, int $x=0, int $y=0) : ImageHelper |
|
| 1541 | + public function crop(int $width, int $height, int $x = 0, int $y = 0) : ImageHelper |
|
| 1542 | 1542 | { |
| 1543 | 1543 | $new = $this->createNewImage($width, $height); |
| 1544 | 1544 | |
@@ -1622,7 +1622,7 @@ discard block |
||
| 1622 | 1622 | */ |
| 1623 | 1623 | public function getColorAt(int $x, int $y) : RGBAColor |
| 1624 | 1624 | { |
| 1625 | - if($x > $this->getWidth() || $y > $this->getHeight()) |
|
| 1625 | + if ($x > $this->getWidth() || $y > $this->getHeight()) |
|
| 1626 | 1626 | { |
| 1627 | 1627 | throw new ImageHelper_Exception( |
| 1628 | 1628 | 'Position out of bounds', |
@@ -1664,7 +1664,7 @@ discard block |
||
| 1664 | 1664 | */ |
| 1665 | 1665 | public function getHash() : string |
| 1666 | 1666 | { |
| 1667 | - if($this->newImage === null) |
|
| 1667 | + if ($this->newImage === null) |
|
| 1668 | 1668 | { |
| 1669 | 1669 | throw new ImageHelper_Exception( |
| 1670 | 1670 | 'No image loaded to create a hash for.', |
@@ -137,8 +137,7 @@ discard block |
||
| 137 | 137 | $this->sourceImage = $resource; |
| 138 | 138 | $this->type = $type; |
| 139 | 139 | $this->info = self::getImageSize($resource); |
| 140 | - } |
|
| 141 | - else |
|
| 140 | + } else |
|
| 142 | 141 | { |
| 143 | 142 | $this->file = $sourceFile; |
| 144 | 143 | if (!file_exists($this->file)) { |
@@ -580,8 +579,7 @@ discard block |
||
| 580 | 579 | if ($this->width <= $this->height) |
| 581 | 580 | { |
| 582 | 581 | $this->resampleByWidth($width); |
| 583 | - } |
|
| 584 | - else |
|
| 582 | + } else |
|
| 585 | 583 | { |
| 586 | 584 | $this->resampleByHeight($height); |
| 587 | 585 | } |
@@ -30,27 +30,27 @@ discard block |
||
| 30 | 30 | */ |
| 31 | 31 | public function __construct(array $size) |
| 32 | 32 | { |
| 33 | - if(!isset($size['width'])) { |
|
| 33 | + if (!isset($size['width'])) { |
|
| 34 | 34 | $size['width'] = $size[0]; |
| 35 | 35 | } |
| 36 | 36 | |
| 37 | - if(!isset($size['height'])) { |
|
| 37 | + if (!isset($size['height'])) { |
|
| 38 | 38 | $size['height'] = $size[1]; |
| 39 | 39 | } |
| 40 | 40 | |
| 41 | - if(!isset($size[0])) { |
|
| 41 | + if (!isset($size[0])) { |
|
| 42 | 42 | $size[0] = $size['width']; |
| 43 | 43 | } |
| 44 | 44 | |
| 45 | - if(!isset($size[1])) { |
|
| 45 | + if (!isset($size[1])) { |
|
| 46 | 46 | $size[1] = $size['height']; |
| 47 | 47 | } |
| 48 | 48 | |
| 49 | - if(!isset($size['channels'])) { |
|
| 49 | + if (!isset($size['channels'])) { |
|
| 50 | 50 | $size['channels'] = 1; |
| 51 | 51 | } |
| 52 | 52 | |
| 53 | - if(!isset($size['bits'])) { |
|
| 53 | + if (!isset($size['bits'])) { |
|
| 54 | 54 | $size['bits'] = -1; |
| 55 | 55 | } |
| 56 | 56 | |
@@ -63,7 +63,7 @@ discard block |
||
| 63 | 63 | */ |
| 64 | 64 | public static function create($arrayOrInstance) : ImageHelper_Size |
| 65 | 65 | { |
| 66 | - if($arrayOrInstance instanceof self) { |
|
| 66 | + if ($arrayOrInstance instanceof self) { |
|
| 67 | 67 | return new self($arrayOrInstance->toArray()); |
| 68 | 68 | } |
| 69 | 69 | |
@@ -37,7 +37,7 @@ discard block |
||
| 37 | 37 | * @param RGBAColor|null $trimColor |
| 38 | 38 | * @throws ImageHelper_Exception |
| 39 | 39 | */ |
| 40 | - public function __construct(ImageHelper $helper, $sourceImage, ?RGBAColor $trimColor=null) |
|
| 40 | + public function __construct(ImageHelper $helper, $sourceImage, ?RGBAColor $trimColor = null) |
|
| 41 | 41 | { |
| 42 | 42 | ImageHelper::requireResource($sourceImage); |
| 43 | 43 | |
@@ -50,7 +50,7 @@ discard block |
||
| 50 | 50 | { |
| 51 | 51 | $targetColor = ColorFactory::createAuto($trimColor); |
| 52 | 52 | |
| 53 | - if($targetColor !== null) |
|
| 53 | + if ($targetColor !== null) |
|
| 54 | 54 | { |
| 55 | 55 | return $targetColor; |
| 56 | 56 | } |
@@ -79,7 +79,7 @@ discard block |
||
| 79 | 79 | ) |
| 80 | 80 | ); |
| 81 | 81 | |
| 82 | - if($img !== false) { |
|
| 82 | + if ($img !== false) { |
|
| 83 | 83 | return $img; |
| 84 | 84 | } |
| 85 | 85 | |