From 745e8cabf492688d9cfa63dbb8a82e956cbbe367 Mon Sep 17 00:00:00 2001 From: Alies Lapatsin Date: Tue, 20 Aug 2024 23:51:10 +0200 Subject: [PATCH] Improve DX by specifying namespace for GD functions Why: some of these functions are optional and can be not available in the installed PHP. When PHP couldn't find functions in the current and root namespaces, it reports about missing function in the current namespace. As result, Error message is misleading. Example: "Call to undefined function Spatie\Image\Drivers\Gd\imageavif()" --- src/Drivers/Gd/GdDriver.php | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/src/Drivers/Gd/GdDriver.php b/src/Drivers/Gd/GdDriver.php index 87589e3..90b211d 100644 --- a/src/Drivers/Gd/GdDriver.php +++ b/src/Drivers/Gd/GdDriver.php @@ -153,20 +153,20 @@ public function save(?string $path = null): static case 'jpg': case 'jpeg': case 'jfif': - imagejpeg($this->image, $path, $this->quality); + \imagejpeg($this->image, $path, $this->quality); break; case 'png': - imagepng($this->image, $path, $this->pngCompression()); + \imagepng($this->image, $path, $this->pngCompression()); break; case 'gif': - imagegif($this->image, $path); + \imagegif($this->image, $path); break; case 'webp': $quality = $this->quality === 100 ? IMG_WEBP_LOSSLESS : $this->quality; - imagewebp($this->image, $path, $quality); + \imagewebp($this->image, $path, $quality); break; case 'avif': - imageavif($this->image, $path, $this->quality); + \imageavif($this->image, $path, $this->quality); break; default: throw UnsupportedImageFormat::make($extension); @@ -188,19 +188,19 @@ public function base64(string $imageFormat = 'jpeg', bool $prefixWithFormat = tr case 'jpg': case 'jpeg': case 'jfif': - imagejpeg($this->image, null, $this->quality); + \imagejpeg($this->image, null, $this->quality); break; case 'png': - imagepng($this->image, null, $this->pngCompression()); + \imagepng($this->image, null, $this->pngCompression()); break; case 'gif': - imagegif($this->image, null); + \imagegif($this->image, null); break; case 'webp': - imagewebp($this->image, null); + \imagewebp($this->image, null); break; case 'avif': - imageavif($this->image, null); + \imageavif($this->image, null); break; default: throw UnsupportedImageFormat::make($imageFormat);