Currently, WMF has implemented some WebP thumbnailing support for images on their infrastructure, at the server level, without modifications to MediaWiki: T27611: Serve optimized WebP thumbnails as alternative to JPEG, PNG
This task is to allow MediaWiki to generate WebP thumbnails in addition to the current thumbnails being generated.
Currently, MediaWiki generates thumbnails with ImageMagick, with the same format as the original file (JPG->JPG, PNG->PNG, GIF-GIF) with some exceptions (SVG->PNG). The idea would be to generate also a WEBP thumbnail in addition to the current one.
While WebP format support is now more widespread, there should be a way for browsers to fallback to the JPG/PNG thumbnail. This would require MediaWiki to use the <picture> HTML element instead of the <img> one. The <picture> element allows to specify a list of sources the browser can choose from. It's a sort of content-negotiation feature on the client level instead of on the server level (which is how WMF has done it). The <picture> element can contain a nested <img> tag for compatibility for browsers that don't support HTML5.
See https://developer.mozilla.org/en-US/docs/Web/HTML/Element/picture
Possible implementation:
- A configuration variable to allow WebP thumbnails in addition to the current ones. Maybe with a list of possible file extensions to support (I'm not sure if animated GIF can be transcoded to WEBP or if browsers support that).
- Use <picture> to render images instead of <img> tag, and add the sources with the WebP variants.