Jump to content

Having issues imagewebp() function not being called properly


denno020

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.