Skip to content

Commit

Permalink
Improve DX by specifying namespace for GD functions (#274)
Browse files Browse the repository at this point in the history
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()"
  • Loading branch information
alies-dev committed Aug 22, 2024
1 parent 5741d42 commit 349be3e
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions src/Drivers/Gd/GdDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
Expand Down

0 comments on commit 349be3e

Please sign in to comment.