supportsFileType#

True when the loaded libgd can read, or with a true second argument write, the image file named by its first argument.

print "can do webp\n" if GD::supportsFileType('photo.webp');
print "can write tga\n" if GD::supportsFileType('out.tga', 1);

libgd judges by the file name’s extension, case-insensitively, so pass a file name: a bare 'webp' has no extension and is always false. libgd is routinely packaged without WebP, AVIF or JXL, and some formats (TGA, XPM) can be read but not written, so asking is worth doing before offering a format to a user.