Skip to content
Advertisement

imagecreatefromweb causing FATAL error which cannot be caught

I have a simple block of code that when fed an invalid file should be able to provide some user feedback, but I am finding the call to imagecreatefromweb** simply stops all PHP processing with a “Fatal error: gd-webp cannot get webp info in ..” straight away.

I have tried to place this in a try catch but this doesn’t make a difference.

How do I catch this error?

JavaScript

I am using PHP7.3.12 via Windows. (Note this code will work when fed a valid .webp file).

** (or imagecreatefromjpg or imagecreatefrompng, etc)

Advertisement

Answer

Use exif_imagetype() to ensure the file is in WEBP format:

JavaScript

Note: use file_exists to ensure the file is really there

User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement