From 8fbbccfa21c56b273fa144fc91b325489f346f46 Mon Sep 17 00:00:00 2001 From: Jeroen De Meerleer Date: Tue, 23 Jul 2024 13:55:20 +0200 Subject: [PATCH] Improved image handling logic The image processing logic has been updated to better handle optional parameters. Previously, the code would always pad and resize the canvas regardless of whether width, height, or canvas dimensions were provided. Now, padding and resizing only occur if the corresponding options are set. This change makes the code more flexible and prevents potential errors when certain parameters are not provided. --- index.php | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/index.php b/index.php index a7abcd8..0ea4a91 100644 --- a/index.php +++ b/index.php @@ -53,9 +53,14 @@ if(isSvg($imagecontent)) { $transparent = (new \Intervention\Image\Colors\Rgb\Color(0,0,0,0)); // to finally create image instances $image = $manager - ->read($imagecontent) - ->pad($options['width'], $options['height'], $transparent) - ->resizeCanvas($options['canvaswidth'], $options['canvasheight'], $transparent); + ->read($imagecontent); + +if(isset($options['width']) || isset($options['height'])) { + $image = $image->pad($options['width'], $options['height'], $transparent); +} +if(isset($options['canvaswidth']) || isset($options['canvasheight'])) { + $image = $image->resizeCanvas($options['canvaswidth'], $options['canvasheight'], $transparent); +} if (isset($options['fill'])) { $image = $image->blendTransparency($options['fill']);