{"record":{"id":"c416dbc5c21288b0","repo":"Intervention/image","slug":"image-source-must-be-of-type-intervention-image-en","errorCode":null,"errorMessage":"Image source must be of type Intervention\\Image\\EncodedImage","messagePattern":"Image source must be of type Intervention\\\\Image\\\\EncodedImage","errorType":"exception","errorClass":"InvalidArgumentException","httpStatus":null,"severity":"error","filePath":"src/Drivers/Gd/Decoders/EncodedImageObjectDecoder.php","lineNumber":43,"sourceCode":"    {\n        return $input instanceof EncodedImageInterface;\n    }\n\n    /**\n     * {@inheritdoc}\n     *\n     * @see DecoderInterface::decode()\n     *\n     * @throws InvalidArgumentException\n     * @throws ImageDecoderException\n     * @throws DriverException\n     * @throws StateException\n     * @throws NotSupportedException\n     */\n    public function decode(mixed $input): ImageInterface\n    {\n        if (!$input instanceof EncodedImageInterface) {\n            throw new InvalidArgumentException('Image source must be of type ' . EncodedImage::class);\n        }\n\n        try {\n            return parent::decode($input->toString());\n        } catch (DecoderException) {\n            throw new ImageDecoderException(EncodedImage::class . ' contains unsupported image type');\n        }\n    }\n}\n","sourceCodeStart":25,"sourceCodeEnd":53,"githubUrl":"https://github.com/Intervention/image/blob/5598b9e39751c34afc5cdee84abef77f92c26f68/src/Drivers/Gd/Decoders/EncodedImageObjectDecoder.php#L25-L53","documentation":"Contract violation of EncodedImageObjectDecoder::decode: the input does not implement EncodedImageInterface. Note the message names the concrete EncodedImage class while the check accepts any EncodedImageInterface implementation — a slight mismatch, but the meaning is the same: only encoded-image value objects belong here. InvalidArgumentException, raised before any decoding.","triggerScenarios":"Calling EncodedImageObjectDecoder->decode() directly with a plain string, GdImage, SplFileInfo, or an unrelated DTO; passing an EncodedImageInterface implementation from a different major version of the library (v2's image objects do not implement the v3 interface); custom routing that forwards every input to this decoder.","commonSituations":"Upgrading Intervention Image from v2 to v3 where older value objects circulate in cached events/queues; manual decoder wiring; serializers that resurrect objects without the interface; feature tests invoking decoders in isolation.","solutions":["Route inputs through ImageManager::read(), which dispatches by type and will send strings/binary to the correct decoder","Construct the expected type first: new EncodedImage($binary, 'image/png') from Intervention\\Image, then pass that object","If interoperating with v2 artifacts, re-create them as v3 objects (read the old bytes, ->encode()) rather than passing old objects","Type-guard: $input instanceof EncodedImageInterface before invoking the decoder"],"exampleFix":"// before\n$decoder = new EncodedImageObjectDecoder();\n$image = $decoder->decode($rawPngString);\n// InvalidArgumentException: Image source must be of type Intervention\\Image\\EncodedImage\n\n// after\n$image = $manager->read(new \\Intervention\\Image\\EncodedImage($rawPngString, 'image/png'));\n// or simply: $image = $manager->read($rawPngString);","handlingStrategy":"type-guard","validationCode":"if (!$input instanceof \\Intervention\\Image\\Interfaces\\EncodedImageInterface) {\n    throw new InvalidArgumentException('Expected EncodedImage, got ' . get_debug_type($input));\n}","typeGuard":"/**\n * @param mixed $input\n */\nfunction isEncodedImage(mixed $input): bool\n{\n    return $input instanceof \\Intervention\\Image\\Interfaces\\EncodedImageInterface;\n}","tryCatchPattern":null,"preventionTips":["Route through ImageManager::read() instead of invoking the decoder directly","After major-version upgrades, re-create cached/queued image objects in the new version's classes","Type-hint EncodedImageInterface in your own signatures"],"tags":["type-error","invalid-argument","encoded-image","decoder","version-migration"],"backgroundTag":"invalid-argument-type","analyzedSha":"5598b9e39751c34afc5cdee84abef77f92c26f68","analyzedAt":"2026-08-23T02:17:31.068Z","schemaVersion":2},"datasetVersion":"2026-08-23T08:06:27.607Z"}