{"record":{"id":"3495c4d22f225557","repo":"Intervention/image","slug":"splfileinfo-contains-unsupported-image-type-3495c4","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/Imagick/Decoders/SplFileInfoImageDecoder.php","lineNumber":55,"sourceCode":"     *\n     * @throws InvalidArgumentException\n     * @throws DirectoryNotFoundException\n     * @throws FileNotFoundException\n     * @throws FileNotReadableException\n     * @throws ImageDecoderException\n     * @throws DriverException\n     * @throws StateException\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":37,"sourceCodeEnd":59,"githubUrl":"https://github.com/Intervention/image/blob/5598b9e39751c34afc5cdee84abef77f92c26f68/src/Drivers/Imagick/Decoders/SplFileInfoImageDecoder.php#L37-L59","documentation":"The file behind the SplFileInfo could not be decoded. Subtlety worth knowing: because ImageDecoderException extends DecoderException, the catch (DecoderException) here also swallows the parent FilePathImageDecoder's more specific errors ('Failed to decode image data from file ...', 'Failed to retrieve image format') and relabels them - so this message can mean a genuinely unsupported format OR a plain corrupt file, with the detail lost.","triggerScenarios":"ImageManager::read(new SplFileInfo($path)) or reading a Symfony UploadedFile whose underlying file is corrupt, has a misleading extension, or is in a format the installed ImageMagick cannot decode (missing WebP/AVIF delegate, policy-blocked coder).","commonSituations":"Laravel/Symfony upload handling where the tmp file is a truncated transfer; extension spoofing (file.php renamed file.png); prod container missing delegates while local dev works.","solutions":["Check the real content of $file->getPathname() with finfo_file() or `file` before reading","Confirm delegate availability: Imagick::queryFormats() should list the target format","Install missing delegates or adjust policy.xml (see the file-based variant of this error)","To recover the precise reason, read the path directly ($manager->read($splFileInfo->getPathname())) so FilePathImageDecoder's specific message surfaces unwrapped"],"exampleFix":"// before\n$image = $manager->read($uploadedFile); // Symfony UploadedFile; shows generic 'unsupported image type'\n\n// after: diagnose via the path to get the precise error\n$image = $manager->read($uploadedFile->getPathname()); // FilePathImageDecoder reports the exact failure","handlingStrategy":"validation","validationCode":"$path = $splFileInfo->getPathname();\n$mime = finfo_file(finfo_open(FILEINFO_MIME_TYPE), $path);\nif (!str_starts_with((string) $mime, 'image/')) {\n    throw new RuntimeException('File is not an image: ' . $mime);\n}\n$image = $manager->read($splFileInfo);","typeGuard":null,"tryCatchPattern":"try {\n    $image = $manager->read($splFileInfo);\n} catch (\\Intervention\\Image\\Exceptions\\ImageDecoderException $e) {\n    // generic label - re-read via ->getPathname() to get the precise underlying error\n    throw $e;\n}","preventionTips":["Validate upload tmp files with finfo_file() before they reach the manager","Remember this message also masks corrupt-file errors, not only unsupported formats"],"tags":["imagick","splfileinfo","uploads","decode","unsupported-format"],"backgroundTag":"image-decode-failed","analyzedSha":"5598b9e39751c34afc5cdee84abef77f92c26f68","analyzedAt":"2026-08-23T02:17:31.068Z","schemaVersion":2},"datasetVersion":"2026-08-23T08:06:27.607Z"}