Intervention/image · error · InvalidArgumentException
Image source must be of type SplFileInfo
Error message
Image source must be of type SplFileInfo
What it means
SplFileInfoImageDecoder only accepts SplFileInfo objects; decode() throws InvalidArgumentException immediately for any other value. Through ImageManager this decoder is auto-selected only for SplFileInfo input, so hitting it usually means invoking the decoder manually or forcing it via the decoders argument of decode().
Source
Thrown at src/Drivers/Gd/Decoders/SplFileInfoImageDecoder.php:50
}
/**
* {@inheritdoc}
*
* @see DecoderInterface::decode()
*
* @throws InvalidArgumentException
* @throws ImageDecoderException
* @throws DriverException
* @throws StateException
* @throws DirectoryNotFoundException
* @throws FileNotFoundException
* @throws FileNotReadableException
*/
public function decode(mixed $input): ImageInterface
{
if (!$input instanceof SplFileInfo) {
throw new InvalidArgumentException('Image source must be of type ' . SplFileInfo::class);
}
try {
return parent::decode(self::filePathFromSplFileInfoOrFail($input));
} catch (DecoderException) {
throw new ImageDecoderException(SplFileInfo::class . ' contains unsupported image type');
}
}
}
View on GitHub (pinned to 5598b9e397)
Solutions
- Pass an SplFileInfo instance: new SplFileInfo($path)
- Or pass the plain path and let the automatic decoder chain select FilePathImageDecoder
- Use $manager->decodeSplFileInfo($splFileInfo) for explicit, typed entry
Example fix
// before $image = $manager->decode($path, SplFileInfoImageDecoder::class); // InvalidArgumentException // after $image = $manager->decode(new SplFileInfo($path), SplFileInfoImageDecoder::class); // or simply: $image = $manager->read($path);
Defensive patterns
Strategy: type-guard
Validate before calling
if (!$input instanceof SplFileInfo) {
$input = new SplFileInfo((string) $input);
}
$image = $manager->decodeSplFileInfo($input); Type guard
function isSplFileInfo(mixed $value): bool
{
return $value instanceof SplFileInfo;
} Try / catch
try {
$image = $decoder->decode($input);
} catch (InvalidArgumentException $e) {
// input was not an SplFileInfo; wrap it and retry
} Prevention
- Prefer $manager->read($anySource) and let the chain pick the decoder
- Type helper parameters as SplFileInfo so the compiler catches misuse
- Avoid forcing specific decoders unless necessary
When it happens
Trigger: $manager->decode($path, SplFileInfoImageDecoder::class) with a plain string, or (new SplFileInfoImageDecoder($driver))->decode('image.png') called directly.
Common situations: Porting code that mixes path strings with SplFileInfo, passing a string to a helper documented to build SplFileInfo, forcing a specific decoder as the second decode() argument.
Understand the failure class
Background: Invalid argument type errors: "must be of type string", "expected X, got Y", and ERR_INVALID_ARG_TYPE explained — this error's family across 15 libraries.
Related errors
- Color object must be of type {ColorInterface::class}
- Base64-encoded data must be either of type string or instanc
- Unsupported image source type "{type}"
- Unsupported media type (MIME) ${mediaType}.
- Failed to read media (MIME) type from data in file path
AI-assisted analysis of Intervention/image@5598b9e397 (2026-08-23).
Data as JSON: /api/errors/2a69ee817f4ef400.
Report an issue: GitHub.