Description
MediaWiki can upload and recognize static WebP images, but thumbnail generation fails when GD is used as the image scaler.
The error displayed on the file page is:
Error creating thumbnail: Image type not supported
The WebP file is correctly handled by WebPHandler. Its MIME type, dimensions, and metadata are detected successfully. PHP GD also reports WebP support and can decode the exact file using imagecreatefromwebp().
However, BitmapHandler::transformGd() does not include image/webp in its $typemap. It therefore rejects the source MIME type before calling GD.
Environment
- MediaWiki: 1.43.9
- PHP: 8.3.31
- PHP SAPI: fpm-fcgi
- Image scaler: GD
- GD version: bundled, 2.1.0 compatible
- GD WebP support: enabled
- imagecreatefromwebp(): available
- imagewebp(): available
- ImageMagick: not enabled
- Installation type: third-party MediaWiki installation
Steps to reproduce
- Install MediaWiki 1.43.9 with PHP GD.
- Ensure that GD was built with WebP support.
- Configure MediaWiki to use GD rather than ImageMagick.
- Allow WebP uploads.
- Upload a valid, static WebP image.
- Add the image to a page with a thumbnail size, for example:
[[File:Example.webp|250px]]
Open or purge the page.
Actual behavior
Thumbnail generation fails with:
Error creating thumbnail: Image type not supported
No image-specific directory or thumbnail is created under images/thumb/.
MediaWiki nevertheless identifies the uploaded image correctly through the API. Example values:
mime: image/webp mediatype: BITMAP width: 795 height: 512
The stored WebP metadata also identifies the image as non-animated:
compression: lossy animated: false transparency: true
Expected behavior
MediaWiki should use imagecreatefromwebp() to decode a static WebP source when GD reports WebP support, then generate the PNG thumbnail requested by WebPHandler::getThumbType().
Investigation
The exact uploaded file was tested through the same PHP-FPM runtime used by MediaWiki.
The following operations succeed:
getimagesize( $source ) exif_imagetype( $source ) mime_content_type( $source ) imagecreatefromwebp( $source ) imagepng( $image, $target )
This confirms that:
- the WebP file is valid;
- the file is readable;
- PHP-FPM is using a GD build with WebP support;
- GD can decode the exact WebP file;
- GD can write a PNG output;
- the destination filesystem is writable.
WebPHandler.php reports GD support through:
protected function hasGDSupport() {
return function_exists( 'gd_info' )
&& ( gd_info()['WebP Support'] ?? false );
}It requests PNG thumbnails through:
public function getThumbType( $ext, $mime, $params = null ) {
return [ 'png', 'image/png' ];
}However, BitmapHandler::transformGd() defines a hard-coded $typemap containing GIF, JPEG, PNG, WBMP, and XBM, but no image/webp entry.
It subsequently checks:
if ( !isset( $typemap[$params['mimeType']] ) ) {
$err = 'Image type not supported';
...
}Since $params['mimeType'] is image/webp, this produces the reported error.
Tested workaround
Adding the following entry to the $typemap in BitmapHandler::transformGd() fixes thumbnail generation:
'image/webp' => [
'imagecreatefromwebp',
'bits',
false,
'imagepng'
],After this change, MediaWiki successfully creates a PNG thumbnail under the expected images/thumb/ path.
The PNG writer is used because WebPHandler::getThumbType() returns:
[ 'png', 'image/png' ]
Suggested fix
Add static WebP input support to BitmapHandler::transformGd() when imagecreatefromwebp() is available.
The fix may also need a regression test confirming that:
- WebPHandler selects GD when GD reports WebP support.
- A static WebP source can be transformed into a PNG thumbnail.
- Animated WebP files remain subject to the existing canRender() restriction.
Additional information
This specifically affects MediaWiki installations using GD. Installations using ImageMagick may not reproduce the problem because they use a different transformation path.
The uploaded test image is static, not animated.
See also T282453, which concerns WebP thumbnail output. This report concerns static WebP input failing specifically in the GD transformation path.