From 652771b3c4230dfb981949dbd5e33afb6bff3d34 Mon Sep 17 00:00:00 2001 From: Bastien Philippe Date: Thu, 9 Dec 2021 12:52:46 +0100 Subject: [PATCH 1/2] Fix php8.1 deprecations --- src/Manipulators/Brightness.php | 6 +++++- src/Manipulators/Contrast.php | 6 +++++- src/Manipulators/Crop.php | 6 +++++- src/Manipulators/Gamma.php | 6 +++++- src/Manipulators/Size.php | 16 ++++++++++++---- src/ServerFactory.php | 8 ++++---- 6 files changed, 36 insertions(+), 12 deletions(-) diff --git a/src/Manipulators/Brightness.php b/src/Manipulators/Brightness.php index f1d44971..256dc3b0 100644 --- a/src/Manipulators/Brightness.php +++ b/src/Manipulators/Brightness.php @@ -5,7 +5,7 @@ use Intervention\Image\Image; /** - * @property string $bri + * @property string|null $bri */ class Brightness extends BaseManipulator { @@ -34,6 +34,10 @@ public function run(Image $image) */ public function getBrightness() { + if (null === $this->bri) { + return; + } + if (!preg_match('/^-*[0-9]+$/', $this->bri)) { return; } diff --git a/src/Manipulators/Contrast.php b/src/Manipulators/Contrast.php index 38fc35c9..86665bb6 100644 --- a/src/Manipulators/Contrast.php +++ b/src/Manipulators/Contrast.php @@ -5,7 +5,7 @@ use Intervention\Image\Image; /** - * @property string $con + * @property string|null $con */ class Contrast extends BaseManipulator { @@ -34,6 +34,10 @@ public function run(Image $image) */ public function getContrast() { + if (null === $this->con) { + return; + } + if (!preg_match('/^-*[0-9]+$/', $this->con)) { return; } diff --git a/src/Manipulators/Crop.php b/src/Manipulators/Crop.php index 78cfc228..9a8428df 100644 --- a/src/Manipulators/Crop.php +++ b/src/Manipulators/Crop.php @@ -5,7 +5,7 @@ use Intervention\Image\Image; /** - * @property string $crop + * @property string|null $crop */ class Crop extends BaseManipulator { @@ -45,6 +45,10 @@ public function run(Image $image) */ public function getCoordinates(Image $image) { + if (null === $this->crop) { + return; + } + $coordinates = explode(',', $this->crop); if (4 !== count($coordinates) or diff --git a/src/Manipulators/Gamma.php b/src/Manipulators/Gamma.php index 2242a909..800dd31f 100644 --- a/src/Manipulators/Gamma.php +++ b/src/Manipulators/Gamma.php @@ -5,7 +5,7 @@ use Intervention\Image\Image; /** - * @property string $gam + * @property string|null $gam */ class Gamma extends BaseManipulator { @@ -34,6 +34,10 @@ public function run(Image $image) */ public function getGamma() { + if (null === $this->gam) { + return; + } + if (!preg_match('/^[0-9]\.*[0-9]*$/', $this->gam)) { return; } diff --git a/src/Manipulators/Size.php b/src/Manipulators/Size.php index 68493634..b5308829 100644 --- a/src/Manipulators/Size.php +++ b/src/Manipulators/Size.php @@ -5,10 +5,10 @@ use Intervention\Image\Image; /** - * @property string $dpr - * @property string $fit - * @property string $h - * @property string $w + * @property string $dpr + * @property string|null $fit + * @property string $h + * @property string $w */ class Size extends BaseManipulator { @@ -119,6 +119,10 @@ public function getHeight() */ public function getFit() { + if (null === $this->fit) { + return 'contain'; + } + if (in_array($this->fit, ['contain', 'fill', 'max', 'stretch'], true)) { return $this->fit; } @@ -424,6 +428,10 @@ public function getCrop() 'crop-bottom-right' => [100, 100, 1.0], ]; + if (null === $this->fit) { + return [50, 50, 1.0]; + } + if (array_key_exists($this->fit, $cropMethods)) { return $cropMethods[$this->fit]; } diff --git a/src/ServerFactory.php b/src/ServerFactory.php index a6819a29..778e7da0 100644 --- a/src/ServerFactory.php +++ b/src/ServerFactory.php @@ -57,13 +57,13 @@ public function getServer() $this->getApi() ); - $server->setSourcePathPrefix($this->getSourcePathPrefix()); - $server->setCachePathPrefix($this->getCachePathPrefix()); + $server->setSourcePathPrefix($this->getSourcePathPrefix() ?: ''); + $server->setCachePathPrefix($this->getCachePathPrefix() ?: ''); $server->setGroupCacheInFolders($this->getGroupCacheInFolders()); $server->setCacheWithFileExtensions($this->getCacheWithFileExtensions()); $server->setDefaults($this->getDefaults()); $server->setPresets($this->getPresets()); - $server->setBaseUrl($this->getBaseUrl()); + $server->setBaseUrl($this->getBaseUrl() ?: ''); $server->setResponseFactory($this->getResponseFactory()); if ($this->getTempDir()) { @@ -259,7 +259,7 @@ public function getManipulators() new Flip(), new Blur(), new Pixelate(), - new Watermark($this->getWatermarks(), $this->getWatermarksPathPrefix()), + new Watermark($this->getWatermarks(), $this->getWatermarksPathPrefix() ?: ''), new Background(), new Border(), new Encode(), From dda39e1f42eb724a434089a745cb375179cdf98e Mon Sep 17 00:00:00 2001 From: Bastien Philippe Date: Thu, 9 Dec 2021 13:53:17 +0100 Subject: [PATCH 2/2] Apply suggestion --- src/Manipulators/Brightness.php | 6 +----- src/Manipulators/Contrast.php | 6 +----- src/Manipulators/Gamma.php | 6 +----- 3 files changed, 3 insertions(+), 15 deletions(-) diff --git a/src/Manipulators/Brightness.php b/src/Manipulators/Brightness.php index 256dc3b0..2a33544e 100644 --- a/src/Manipulators/Brightness.php +++ b/src/Manipulators/Brightness.php @@ -34,11 +34,7 @@ public function run(Image $image) */ public function getBrightness() { - if (null === $this->bri) { - return; - } - - if (!preg_match('/^-*[0-9]+$/', $this->bri)) { + if (null === $this->bri || !preg_match('/^-*[0-9]+$/', $this->bri)) { return; } diff --git a/src/Manipulators/Contrast.php b/src/Manipulators/Contrast.php index 86665bb6..c2cf9140 100644 --- a/src/Manipulators/Contrast.php +++ b/src/Manipulators/Contrast.php @@ -34,11 +34,7 @@ public function run(Image $image) */ public function getContrast() { - if (null === $this->con) { - return; - } - - if (!preg_match('/^-*[0-9]+$/', $this->con)) { + if (null === $this->con || !preg_match('/^-*[0-9]+$/', $this->con)) { return; } diff --git a/src/Manipulators/Gamma.php b/src/Manipulators/Gamma.php index 800dd31f..035bb8de 100644 --- a/src/Manipulators/Gamma.php +++ b/src/Manipulators/Gamma.php @@ -34,11 +34,7 @@ public function run(Image $image) */ public function getGamma() { - if (null === $this->gam) { - return; - } - - if (!preg_match('/^[0-9]\.*[0-9]*$/', $this->gam)) { + if (null === $this->gam || !preg_match('/^[0-9]\.*[0-9]*$/', $this->gam)) { return; }