Intervention/image · error · Intervention\Image\Exceptions\InvalidArgumentException
Image source must be data uri scheme of type string or
Error message
Image source must be data uri scheme of type string or
What it means
Thrown by DataUriImageDecoder::decode() when the input is neither a string nor a DataUri instance. The data URI decoder accepts only those two shapes; arrays, resources, null, or other objects are rejected with this InvalidArgumentException before parsing is attempted.
Source
Thrown at src/Drivers/Imagick/Decoders/DataUriImageDecoder.php:51
* @see DecoderInterface::decode()
*
* @throws InvalidArgumentException
* @throws ImageDecoderException
* @throws DriverException
* @throws StateException
*/
public function decode(mixed $input): ImageInterface
{
if ($input instanceof DataUri) {
try {
return parent::decode($input->data());
} catch (DecoderException) {
throw new ImageDecoderException('Data Uri contains unsupported image type');
}
}
if (!is_string($input)) {
throw new InvalidArgumentException(
'Image source must be data uri scheme of type string or ' . DataUri::class,
);
}
try {
return parent::decode(DataUri::parse($input)->data());
} catch (DecoderException) {
throw new ImageDecoderException('Data Uri contains unsupported image type');
}
}
}
View on GitHub (pinned to 5598b9e397)
Solutions
- Cast to string before passing: $manager->read((string) $value) when the value is string-compatible
- Null-check optional fields and fail with validation instead
- When calling decoders manually, route through supports() first, as the manager does
Example fix
// before: value object passed to a data-uri decoder chain $image = $decoder->decode($psr7Uri); // object, not string // after: cast to the string form $image = $decoder->decode((string) $psr7Uri);
Defensive patterns
Strategy: type-guard
Validate before calling
if (!is_string($input) && !$input instanceof DataUri) {
throw new InvalidArgumentException('input must be string or DataUri');
}
$image = $manager->read($input); Type guard
function isDataUriInput(mixed $value): bool
{
return is_string($value) || $value instanceof DataUri;
} Try / catch
use Intervention\Image\Exceptions\InvalidArgumentException;
try {
$image = $manager->read($input);
} catch (InvalidArgumentException $e) {
// caller bug: cast the value to string before passing
throw $e;
} Prevention
- Cast string-compatible objects to string at your wrapper boundary
- Null-check optional inputs before decode calls
- When wiring custom decoder chains, always consult supports() first like ImageManager does
When it happens
Trigger: Invoking the DataUri decoder directly (custom decoder chains, unit tests) with e.g. an array of URI parts, a PSR-7 Uri object, null, or an Integerish value. Through ImageManager::read() this is rare because supports() (couldBeDataUrl) only routes strings/DataUri-shaped input here — but a custom decoder setup can bypass that gate.
Common situations: Custom SpecializableDecoder pipelines wired by hand; passing a value object that stringifies to a data URI (it is not Stringable-accepted here — must be string or DataUri); null inputs after optional-field lookups.
Related errors
- Unable to Base64-decode image from string
- Image source must be binary data of type string or instance
- Image source must be of type
- Input is not valid Base64-encoded data
- Image source must be data uri scheme of type string or Inter
AI-assisted analysis of Intervention/image@5598b9e397 (2026-08-23).
Data as JSON: /api/errors/30efc0840db09bb7.
Report an issue: GitHub.