Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Undefined constant "Intervention\Image\Drivers\Gd\Encoders\IMG_WEBP_LOSSLESS" #1416

Open
kmuharam opened this issue Jan 10, 2025 · 6 comments

Comments

@kmuharam
Copy link

Describe the bug

Trying to process an uploaded image, I receive an exception:
Undefined constant "Intervention\Image\Drivers\Gd\Encoders\IMG_WEBP_LOSSLESS".

Please note, if I reduce the quality to 99 (or any number but 100) everything works fine.

This issue seems to be more related to intervention/image package.

Code Example

use Ramsey\Uuid\Uuid;
use Illuminate\Support\Facades\Storage;
use Intervention\Image\Laravel\Facades\Image;
use Illuminate\Http\JsonResponse;

class Service {
    // ...
    public function store(CreateRequest $request): JsonResponse
    {
        // ...
        $portraitImageName = Uuid::uuid4() . '.webp';
        $interventionPortraitImage = Image::read($request->file("portrait_cover_image"));

        Storage::disk('s3')->put("/portal/blog/posts/images/{$portraitImageName}", $interventionPortraitImage->toWebp(100));
        // ...
    }
    // ...
}

Expected Behavior

Exploring file: intervention/image/src/Drivers/Gd/EncodersWebpEncoder.php:

    // ... Line 20
    $quality = $this->quality === 100 ? IMG_WEBP_LOSSLESS : $this->quality;
    // ... Line 22

The constant IMG_WEBP_LOSSLESS should be defined in appropriate file.

Environment (please complete the following information):

  • PHP Version: 8.2
  • OS: AlmaLinux 9.5
  • Intervention Image Version: 1.3.0
  • GD or Imagick: GD
@olivervogel olivervogel transferred this issue from Intervention/image-laravel Jan 10, 2025
@olivervogel
Copy link
Member

It seems your GD extension does not support Webp format. You can check with:

function_exists('imagewebp');

@kmuharam
Copy link
Author

Hello @olivervogel

Psy Shell v0.12.7 (PHP 8.2.25 — cli) by Justin Hileman
> function_exists('imagewebp');
= true

This extension and intervention both work perfectly if set any value other than 100.

@olivervogel
Copy link
Member

Thats strange. IMG_WEBP_LOSSLESS is supported as of PHP 8.1.0 and is a predefined constant of GD library. If you have GD it should be there.

@kmuharam
Copy link
Author

kmuharam commented Jan 10, 2025

I have been playing around trying to figure this out, depending on the PHP docs:

GD

imagewebp() can now do lossless WebP encoding by passing IMG_WEBP_LOSSLESS as the quality.

This constant is only defined, if the used libgd supports lossless WebP encoding.

I have tried also to list all defined constants and did not find IMG_WEBP_LOSSLESS.

It seems like the existence of the constant depends on the libgd package provided by the OS / Repo and not always present.

@olivervogel
Copy link
Member

olivervogel commented Jan 11, 2025

Ok thanks. I actually didn't knew that the constant is only defined if libgd is compiled with support for lossless webp encoding.

The patch 4476d94 is already included and will be available in the next release.

@kmuharam
Copy link
Author

Ok, thank you for this great package 💚.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants