Intervention/image · error · Intervention\Image\Exceptions\InvalidArgumentException
Image source must be of type
Error message
Image source must be of type
What it means
Thrown by EncodedImageObjectDecoder::decode() when the input is not an EncodedImageInterface (the interface behind EncodedImage — the object toBytes()/encode() return). This decoder only re-ingests previously encoded image objects; any other value is rejected up front.
Source
Thrown at src/Drivers/Imagick/Decoders/EncodedImageObjectDecoder.php:41
public function supports(mixed $input): bool
{
return $input instanceof EncodedImageInterface;
}
/**
* {@inheritdoc}
*
* @see DecoderInterface::decode()
*
* @throws InvalidArgumentException
* @throws DriverException
* @throws StateException
* @throws ImageDecoderException
*/
public function decode(mixed $input): ImageInterface
{
if (!$input instanceof EncodedImageInterface) {
throw new InvalidArgumentException('Image source must be of type ' . EncodedImage::class);
}
try {
return parent::decode($input->toString());
} catch (DecoderException) {
throw new ImageDecoderException(EncodedImage::class . ' contains unsupported image type');
}
}
}
View on GitHub (pinned to 5598b9e397)
Solutions
- Pass the EncodedImage object itself, not ->toString() output (strings route to the binary decoder)
- Type-hint the parameter as EncodedImageInterface so PHP rejects mismatches earlier
- After upgrading the library, flush cached/queued EncodedImage payloads
Example fix
// before: string passed where the decoder wants the object $decoded = $manager->read($image->toPng()->toString()); // after: pass the EncodedImage object $decoded = $manager->read($image->toPng());
Defensive patterns
Strategy: type-guard
Validate before calling
if (!$input instanceof EncodedImageInterface) {
throw new InvalidArgumentException('expected EncodedImageInterface, got ' . get_debug_type($input));
}
$image = $manager->read($input); Type guard
function isEncodedImageObject(mixed $value): bool
{
return $value instanceof EncodedImageInterface;
} Try / catch
use Intervention\Image\Exceptions\InvalidArgumentException;
try {
$image = $manager->read($input);
} catch (InvalidArgumentException $e) {
// pass the EncodedImage object itself, or fix decoder chain wiring
throw $e;
} Prevention
- Pass encode() results as objects; pass their ->toString() only when you mean the binary path
- Type-hint EncodedImageInterface in custom pipelines
- Flush cached/queued EncodedImage payloads after major-version upgrades
When it happens
Trigger: Calling this decoder (directly, or in a hand-wired decoder chain) with a plain string, an Imagick object, or an EncodedImage from a different major version whose class no longer implements the interface. Note: through ImageManager::read() the supports() check (instanceof EncodedImageInterface) prevents this error for non-matching input.
Common situations: Custom decoder pipelines that skip supports(); upgrading intervention/image across major versions while old EncodedImage instances circulate in caches/queues; passing the string from ->toString() where the object itself was expected.
Related errors
- Image source must be binary data of type string or instance
- Image source must be data uri scheme of type string or
- Input is not valid Base64-encoded data
- Image source must be of type Intervention\Image\EncodedImage
- Unable to Base64-decode image from string
AI-assisted analysis of Intervention/image@5598b9e397 (2026-08-23).
Data as JSON: /api/errors/ae82b2097cbbae27.
Report an issue: GitHub.