In a Python web application, WebP images can be created on the fly using the Python Image Library as demonstrated in this StackOverflow response. On Debian/Ubuntu, the libwebp-dev library must be installed before installing PIL.
WordPress
Use the image_editor_ouptut_format hook to map the mimetypes for jpeg and jpg images to the mimetype for WebP images. Add the following to a theme's functions.php file:
Any JPG image will then have WebP thumbnails generated, provided the image is bigger than the thumbnail size. If thumbnails need to be manually regenerated after adding this function, the WP CLI provides the media regenerate command to do so:
$ wp media regenerate --image_size=spam_and_eggs
To create a new thumbnail size, define it in the functions.php file with the add_image_size() method:
add_image_size('spam', 640, 400, true);
Use a WebP image as a background image with a JPG fallback