{"record":{"id":"f11f8afc720c9578","repo":"Intervention/image","slug":"splfileinfo-contains-unsupported-image-type","errorCode":null,"errorMessage":"SplFileInfo contains unsupported image type","messagePattern":"SplFileInfo contains unsupported image type","errorType":"exception","errorClass":"ImageDecoderException","httpStatus":null,"severity":"error","filePath":"src/Drivers/Gd/Decoders/SplFileInfoImageDecoder.php","lineNumber":56,"sourceCode":"     *\n     * @throws InvalidArgumentException\n     * @throws ImageDecoderException\n     * @throws DriverException\n     * @throws StateException\n     * @throws DirectoryNotFoundException\n     * @throws FileNotFoundException\n     * @throws FileNotReadableException\n     */\n    public function decode(mixed $input): ImageInterface\n    {\n        if (!$input instanceof SplFileInfo) {\n            throw new InvalidArgumentException('Image source must be of type ' . SplFileInfo::class);\n        }\n\n        try {\n            return parent::decode(self::filePathFromSplFileInfoOrFail($input));\n        } catch (DecoderException) {\n            throw new ImageDecoderException(SplFileInfo::class . ' contains unsupported image type');\n        }\n    }\n}\n","sourceCodeStart":38,"sourceCodeEnd":60,"githubUrl":"https://github.com/Intervention/image/blob/5598b9e39751c34afc5cdee84abef77f92c26f68/src/Drivers/Gd/Decoders/SplFileInfoImageDecoder.php#L38-L60","documentation":"The file behind the SplFileInfo exists and is readable, but no decoder in the GD driver chain could parse its contents, so the DecoderException is rethrown as 'unsupported image type'. The bytes are a format this GD build cannot read (WebP, AVIF, TIFF, BMP depending on compile flags) or corrupt data.","triggerScenarios":"$manager->read(new SplFileInfo('photo.webp')) on PHP whose GD lacks WebP support; a file whose extension does not match real content; an empty or zero-byte file that passed the readable check.","commonSituations":"Shared hosting or distro PHP where GD was compiled without webp/avif, processing user uploads by extension only, zero-byte files after a failed upload, files renamed to .jpg that are actually something else.","solutions":["Check gd_info() for the formats the build supports (WebP Support, AVIF Support, etc.)","Use the Imagick driver when WebP/AVIF/TIFF input must be processed","Convert the file upstream (imagemagick CLI, cloud converter) to PNG/JPEG","Sniff the real MIME type with finfo instead of trusting the extension before handing the file to the manager"],"exampleFix":"// before\n$image = $manager->read(new SplFileInfo('photo.webp')); // GD without webp\n\n// after\nif (pathinfo('photo.webp', PATHINFO_EXTENSION) === 'webp' && !(gd_info()['WebP Support'] ?? false)) {\n    $manager = ImageManager::usingDriver(ImagickDriver::class);\n}\n$image = $manager->read(new SplFileInfo('photo.webp'));","handlingStrategy":"validation","validationCode":"$formats = gd_info();\nif (str_ends_with(strtolower($file), '.webp') && !($formats['WebP Support'] ?? false)) {\n    throw new RuntimeException('GD build lacks WebP support');\n}","typeGuard":null,"tryCatchPattern":"try {\n    $image = $manager->read(new SplFileInfo($file));\n} catch (ImageDecoderException $e) {\n    // retry with an Imagick-driver manager or reject the file\n}","preventionTips":["Sniff MIME type of uploads instead of trusting extensions","Document which formats your GD build supports and test for them at boot","Keep an Imagick fallback path for exotic formats"],"tags":["unsupported-format","gd","webp","file-upload"],"backgroundTag":"unsupported-image-format","analyzedSha":"5598b9e39751c34afc5cdee84abef77f92c26f68","analyzedAt":"2026-08-23T02:17:31.068Z","schemaVersion":2},"datasetVersion":"2026-08-23T08:06:27.607Z"}