{"record":{"id":"52e4c06a755d9769","repo":"Intervention/image","slug":"image-source-must-be-data-uri-scheme-of-type-strin","errorCode":null,"errorMessage":"Image source must be data uri scheme of type string or Intervention\\Image\\DataUri","messagePattern":"Image source must be data uri scheme of type string or Intervention\\\\Image\\\\DataUri","errorType":"exception","errorClass":"InvalidArgumentException","httpStatus":null,"severity":"error","filePath":"src/Drivers/Gd/Decoders/DataUriImageDecoder.php","lineNumber":54,"sourceCode":"     *\n     * @throws InvalidArgumentException\n     * @throws DriverException\n     * @throws ImageDecoderException\n     * @throws StateException\n     * @throws NotSupportedException\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":36,"sourceCodeEnd":66,"githubUrl":"https://github.com/Intervention/image/blob/5598b9e39751c34afc5cdee84abef77f92c26f68/src/Drivers/Gd/Decoders/DataUriImageDecoder.php#L36-L66","documentation":"Contract violation of DataUriImageDecoder::decode: the input is neither a DataUri instance nor a PHP string (e.g. null, array, int, or another object). The decoder cannot interpret such a value as a data URI, so an InvalidArgumentException is thrown. In the normal ImageManager chain this is pre-filtered by supports() (only 'data:'-prefixed strings or DataUri objects), so it mainly bites on direct decoder usage or custom routing.","triggerScenarios":"Calling DataUriImageDecoder->decode() manually with a non-string value; passing a PSR-7 Uri object, an SplFileInfo, or null from an optional request field; feeding the output of DataUri::parse() on a failure path that returned a non-string sentinel.","commonSituations":"Custom pipelines that pick decoders explicitly; refactors that changed upstream types; nullable inputs reaching the decoder after a skipped validation step; tests exercising decoder contracts with mixed values.","solutions":["Route through ImageManager::read(), whose supports() checks (str_starts_with($input, 'data:') or DataUriInterface) select the right decoder","Type-guard before calling: is_string($input) || $input instanceof DataUri","Normalize inputs early: cast objects to string, handle null with a default or an error","If the input is a bare base64 string (no data: prefix), send it to the base64 path instead of the data-URI decoder"],"exampleFix":"// before\n$decoder = new DataUriImageDecoder();\n$image = $decoder->decode($request->input('logo')); // null when field absent\n// InvalidArgumentException: Image source must be data uri scheme ...\n\n// after\n$value = $request->input('logo');\nif (is_string($value) && str_starts_with($value, 'data:')) {\n    $image = $manager->read($value);\n} else {\n    throw new InvalidArgumentException('logo must be a data URI string.');\n}","handlingStrategy":"type-guard","validationCode":"if (!is_string($input) && !$input instanceof \\Intervention\\Image\\DataUri) {\n    throw new InvalidArgumentException('Expected data URI string or DataUri object, got ' . get_debug_type($input));\n}","typeGuard":"/**\n * @param mixed $input\n */\nfunction isDataUriInput(mixed $input): bool\n{\n    return $input instanceof \\Intervention\\Image\\DataUri\n        || (is_string($input) && str_starts_with($input, 'data:'));\n}","tryCatchPattern":null,"preventionTips":["Use ImageManager::read() so supports() routing picks the right decoder","Null-check optional request fields before passing them on","Document the expected input shape where data URIs enter your API"],"tags":["type-error","invalid-argument","data-uri","decoder","php"],"backgroundTag":"invalid-argument-type","analyzedSha":"5598b9e39751c34afc5cdee84abef77f92c26f68","analyzedAt":"2026-08-23T02:17:31.068Z","schemaVersion":2},"datasetVersion":"2026-08-23T08:06:27.607Z"}