{"record":{"id":"30efc0840db09bb7","repo":"Intervention/image","slug":"image-source-must-be-data-uri-scheme-of-type-strin-30efc0","errorCode":null,"errorMessage":"Image source must be data uri scheme of type string or ","messagePattern":"Image source must be data uri scheme of type string or ","errorType":"exception","errorClass":"Intervention\\Image\\Exceptions\\InvalidArgumentException","httpStatus":null,"severity":"error","filePath":"src/Drivers/Imagick/Decoders/DataUriImageDecoder.php","lineNumber":51,"sourceCode":"     * @see DecoderInterface::decode()\n     *\n     * @throws InvalidArgumentException\n     * @throws ImageDecoderException\n     * @throws DriverException\n     * @throws StateException\n     */\n    public function decode(mixed $input): ImageInterface\n    {\n        if ($input instanceof DataUri) {\n            try {\n                return parent::decode($input->data());\n            } catch (DecoderException) {\n                throw new ImageDecoderException('Data Uri contains unsupported image type');\n            }\n        }\n\n        if (!is_string($input)) {\n            throw new InvalidArgumentException(\n                'Image source must be data uri scheme of type string or ' . DataUri::class,\n            );\n        }\n\n        try {\n            return parent::decode(DataUri::parse($input)->data());\n        } catch (DecoderException) {\n            throw new ImageDecoderException('Data Uri contains unsupported image type');\n        }\n    }\n}\n","sourceCodeStart":33,"sourceCodeEnd":63,"githubUrl":"https://github.com/Intervention/image/blob/5598b9e39751c34afc5cdee84abef77f92c26f68/src/Drivers/Imagick/Decoders/DataUriImageDecoder.php#L33-L63","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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"],"exampleFix":"// before: value object passed to a data-uri decoder chain\n$image = $decoder->decode($psr7Uri); // object, not string\n\n// after: cast to the string form\n$image = $decoder->decode((string) $psr7Uri);","handlingStrategy":"type-guard","validationCode":"if (!is_string($input) && !$input instanceof DataUri) {\n    throw new InvalidArgumentException('input must be string or DataUri');\n}\n$image = $manager->read($input);","typeGuard":"function isDataUriInput(mixed $value): bool\n{\n    return is_string($value) || $value instanceof DataUri;\n}","tryCatchPattern":"use Intervention\\Image\\Exceptions\\InvalidArgumentException;\n\ntry {\n    $image = $manager->read($input);\n} catch (InvalidArgumentException $e) {\n    // caller bug: cast the value to string before passing\n    throw $e;\n}","preventionTips":["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"],"tags":["data-uri","input-validation","type-error","decoding"],"backgroundTag":"invalid-image-input-type","analyzedSha":"5598b9e39751c34afc5cdee84abef77f92c26f68","analyzedAt":"2026-08-23T02:17:31.068Z","schemaVersion":2},"datasetVersion":"2026-08-23T08:06:27.607Z"}