Intervention/image · error · Intervention\Image\Exceptions\ImageDecoderException

Data Uri contains unsupported image type

Error message

Data Uri contains unsupported image type

What it means

Thrown by DataUriImageDecoder::decode() when the input is a DataUri object but decoding its embedded binary data fails — parent BinaryImageDecoder raised a DecoderException, remapped to this ImageDecoderException. The data URI structure was fine; the bytes behind it are not an image this ImageMagick can read.

Source

Thrown at src/Drivers/Imagick/Decoders/DataUriImageDecoder.php:46

    }

    /**
     * {@inheritdoc}
     *
     * @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

  1. Whelist media types before reading: only allow data:image/png, jpeg, gif, webp
  2. For SVG support install the rsvg delegate or convert SVGs to raster before ingest
  3. Catch ImageDecoderException and surface an 'unsupported image type' validation error

Example fix

// before: any DataUri accepted
$image = $manager->read(DataUri::parse($input));

// after: gate on media type
$uri = DataUri::parse($input);
if (!in_array($uri->mediaType(), ['image/png', 'image/jpeg', 'image/gif', 'image/webp'], true)) {
    throw new InvalidArgumentException('Unsupported data URI media type');
}
$image = $manager->read($uri);
Defensive patterns

Strategy: try-catch

Validate before calling

$uri = DataUri::parse((string) $input);
$allowed = ['image/png', 'image/jpeg', 'image/gif', 'image/webp'];
if (!in_array($uri->mediaType(), $allowed, true)) {
    throw new InvalidArgumentException('data URI media type not allowed');
}
$image = $manager->read($uri);

Type guard

function isAllowedDataUri(DataUri $uri, array $allowed): bool
{
    return in_array($uri->mediaType(), $allowed, true);
}

Try / catch

use Intervention\Image\Exceptions\ImageDecoderException;

try {
    $image = $manager->read($dataUri);
} catch (ImageDecoderException $e) {
    return back()->withErrors(['image' => 'data URI contains an unsupported image type']);
}

Prevention

When it happens

Trigger: Passing a DataUri object to $manager->read() (or the decoder directly) whose media type/data is e.g. data:application/pdf, a data:image/svg+xml string without SVG delegates, or an image whose base64 body is truncated so the decoded bytes are unparseable.

Common situations: Accepting arbitrary data URIs from users (rich-text editors embed PDF icons, SVGs); SVG support differing between dev (with rsvg) and production (without); truncation of very long URIs by proxies or database column limits.

Related errors


AI-assisted analysis of Intervention/image@5598b9e397 (2026-08-23). Data as JSON: /api/errors/d4a6b2a24660b795. Report an issue: GitHub.