denno020 Posted October 2, 2017 Share Posted October 2, 2017 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 Quote Link to comment https://forums.phpfreaks.com/topic/305173-having-issues-imagewebp-function-not-being-called-properly/ Share on other sites More sharing options...
requinix Posted October 2, 2017 Share Posted October 2, 2017 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. Quote Link to comment https://forums.phpfreaks.com/topic/305173-having-issues-imagewebp-function-not-being-called-properly/#findComment-1552221 Share on other sites More sharing options...
denno020 Posted October 2, 2017 Author Share Posted October 2, 2017 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? Quote Link to comment https://forums.phpfreaks.com/topic/305173-having-issues-imagewebp-function-not-being-called-properly/#findComment-1552222 Share on other sites More sharing options...
denno020 Posted October 2, 2017 Author Share Posted October 2, 2017 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 Quote Link to comment https://forums.phpfreaks.com/topic/305173-having-issues-imagewebp-function-not-being-called-properly/#findComment-1552223 Share on other sites More sharing options...
requinix Posted October 2, 2017 Share Posted October 2, 2017 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. Quote Link to comment https://forums.phpfreaks.com/topic/305173-having-issues-imagewebp-function-not-being-called-properly/#findComment-1552235 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.