{"record":{"id":"ae82b2097cbbae27","repo":"Intervention/image","slug":"image-source-must-be-of-type","errorCode":null,"errorMessage":"Image source must be of type ","messagePattern":"Image source must be of type ","errorType":"exception","errorClass":"Intervention\\Image\\Exceptions\\InvalidArgumentException","httpStatus":null,"severity":"error","filePath":"src/Drivers/Imagick/Decoders/EncodedImageObjectDecoder.php","lineNumber":41,"sourceCode":"    public function supports(mixed $input): bool\n    {\n        return $input instanceof EncodedImageInterface;\n    }\n\n    /**\n     * {@inheritdoc}\n     *\n     * @see DecoderInterface::decode()\n     *\n     * @throws InvalidArgumentException\n     * @throws DriverException\n     * @throws StateException\n     * @throws ImageDecoderException\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":23,"sourceCodeEnd":51,"githubUrl":"https://github.com/Intervention/image/blob/5598b9e39751c34afc5cdee84abef77f92c26f68/src/Drivers/Imagick/Decoders/EncodedImageObjectDecoder.php#L23-L51","documentation":"Thrown by EncodedImageObjectDecoder::decode() when the input is not an EncodedImageInterface (the interface behind EncodedImage — the object toBytes()/encode() return). This decoder only re-ingests previously encoded image objects; any other value is rejected up front.","triggerScenarios":"Calling this decoder (directly, or in a hand-wired decoder chain) with a plain string, an Imagick object, or an EncodedImage from a different major version whose class no longer implements the interface. Note: through ImageManager::read() the supports() check (instanceof EncodedImageInterface) prevents this error for non-matching input.","commonSituations":"Custom decoder pipelines that skip supports(); upgrading intervention/image across major versions while old EncodedImage instances circulate in caches/queues; passing the string from ->toString() where the object itself was expected.","solutions":["Pass the EncodedImage object itself, not ->toString() output (strings route to the binary decoder)","Type-hint the parameter as EncodedImageInterface so PHP rejects mismatches earlier","After upgrading the library, flush cached/queued EncodedImage payloads"],"exampleFix":"// before: string passed where the decoder wants the object\n$decoded = $manager->read($image->toPng()->toString());\n\n// after: pass the EncodedImage object\n$decoded = $manager->read($image->toPng());","handlingStrategy":"type-guard","validationCode":"if (!$input instanceof EncodedImageInterface) {\n    throw new InvalidArgumentException('expected EncodedImageInterface, got ' . get_debug_type($input));\n}\n$image = $manager->read($input);","typeGuard":"function isEncodedImageObject(mixed $value): bool\n{\n    return $value instanceof EncodedImageInterface;\n}","tryCatchPattern":"use Intervention\\Image\\Exceptions\\InvalidArgumentException;\n\ntry {\n    $image = $manager->read($input);\n} catch (InvalidArgumentException $e) {\n    // pass the EncodedImage object itself, or fix decoder chain wiring\n    throw $e;\n}","preventionTips":["Pass encode() results as objects; pass their ->toString() only when you mean the binary path","Type-hint EncodedImageInterface in custom pipelines","Flush cached/queued EncodedImage payloads after major-version upgrades"],"tags":["type-error","encoded-image","input-validation","decoding"],"backgroundTag":"invalid-image-input-type","analyzedSha":"5598b9e39751c34afc5cdee84abef77f92c26f68","analyzedAt":"2026-08-23T02:17:31.068Z","schemaVersion":2},"datasetVersion":"2026-08-23T08:06:27.607Z"}