Jump to content

Having issues imagewebp() function not being called properly


Recommended Posts

I'm having a weird issue with the aforementioned function inside my site. Here is an excerpt of code:

 

 

if ($extension == 'jpg' || $extension == 'jpeg') {
 
    $isSaved = imagejpeg($image, $filename, $imageQuality);
 
} elseif ($extension == 'gif') {
 
    $isSaved = imagegif($image, $filename);
 
} elseif ($extension == 'png') {
 
    if ($imageQuality >= 100) {
        $imageQuality = 0;
    } elseif ($imageQuality <= 0) {
        $imageQuality = 10;
    } else {
        $imageQuality = round((100 - $imageQuality) / 10);
    }
 
    $isSaved = imagepng($image, $filename, intval($imageQuality));
 
} elseif ($extension == 'webp') {
 
    $isSaved = imagewebp($image, $filename, $imageQuality);
 
} else {
 
    throw new Exception(sprintf('Image format "%s" not supported.', $extension), self::ERROR_NOT_SUPPORTED_FORMAT);
 
}

 

The issue is with the webp section, when this code runs (having passed a webp image to it), I get this exception

 

 

Fatal error: Call to undefined function Image\Core\imagewebp() in ......

 

To me it looks like PHP isn't picking up the function as a native PHP function.

 

I am able to use this code perfectly fine on my development machine (windows machine using WAMP with PHP7), but the issue seems to arise when this code is run on my production server. I have been in touch with my hosting provider just now, and they weren't able to enlighten me at all, actually telling me that I need to check the scripts or with a developer that can fix it. The production server is also running PHP7, and webp appears to be enabled (checked using phpinfo())

 

Does anyone know how I could continue to debug this issue?

 

Thanks

Denno

When looking for a function PHP checks the current namespace first and then the global namespace. If it can't find the function in either then the error message will call it by the namespaced name.

 

http://php.net/manual/en/image.requirements.php

 

The format of images you are able to manipulate depend on the version of GD you install, and any other libraries GD might need to access those image formats.

So the PHP+GD installed on your server does not support WebP.

Thanks for the response.

 

How would I check the version of GD that is installed? I did suspect this could be the problem, but I didn't realise they were installed separately, so I (apparently wrongly) assumed that it was inside PHP itself.

 

Also, as I mentioned, when running phpinfo() on the production server, it lists webp in the following two sections:

 

 

HTTP_ACCEPT text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8
$_SERVER['HTTP_ACCEPT'] text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8

 

Is this not related to GD?

Update: I have got back in touch with the hosting provider and am speaking to a different person now, and they're telling me that imagewebp isn't enabled and that I can't get it enabled because it's not supported on shared hosting. So seems there is nothing I can do about it.

 

Thanks anyway

How would I check the version of GD that is installed?

It's not so much the version of GD as it is what it was made to support at the time, which isn't really something you can check with phpinfo().

 

Is this not related to GD?

Not in the slightest.
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.