{"record":{"id":"75ebb0f4e2ca48f6","repo":"Intervention/image","slug":"contains-unsupported-image-type","errorCode":null,"errorMessage":" contains unsupported image type","messagePattern":" contains unsupported image type","errorType":"exception","errorClass":"Intervention\\Image\\Exceptions\\ImageDecoderException","httpStatus":null,"severity":"error","filePath":"src/Drivers/Imagick/Decoders/EncodedImageObjectDecoder.php","lineNumber":47,"sourceCode":"     * {@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":29,"sourceCodeEnd":51,"githubUrl":"https://github.com/Intervention/image/blob/5598b9e39751c34afc5cdee84abef77f92c26f68/src/Drivers/Imagick/Decoders/EncodedImageObjectDecoder.php#L29-L51","documentation":"Thrown by the Imagick driver when an EncodedImage object is read but its binary payload cannot be parsed. EncodedImageObjectDecoder hands the bytes to BinaryImageDecoder, which calls Imagick::readImageBlob(); when that throws a DecoderException, it is swallowed and rethrown as this ImageDecoderException. So the PHP type is fine - the bytes inside the EncodedImage are what ImageMagick cannot decode.","triggerScenarios":"ImageManager::read() with an EncodedImage instance (e.g. one built from cached/DB-stored bytes or produced by $image->encode()) whose payload is truncated, corrupt, or in a format the installed ImageMagick has no coder/delegate for (AVIF, HEIC, WebP, SVG). An empty payload throws a different InvalidArgumentException upstream; this message specifically covers readImageBlob failure.","commonSituations":"Re-reading an encoded image whose bytes were truncated in a cache/DB blob column; base64 decoding that silently produced garbage; dev machine has libwebp/libheif installed but the production slim container does not; SVG passed while ImageMagick was built without RSVG; ImageMagick policy.xml disabling a coder.","solutions":["Inspect the payload before reading: check strlen() and magic bytes with finfo_buffer() or getimagesizefromstring() to confirm it is a complete, valid image","Check delegate support in the failing environment: var_dump(Imagick::queryFormats()) and confirm the needed format (WEBP, AVIF, HEIC, SVG) is listed","Install the missing ImageMagick delegates (libwebp, libavif, libheif, librsvg) and/or use a PHP image that bundles the imagick extension with them","If the payload is truncated at the source, fix the producer (enlarge the blob column, store on disk, verify base64 round-trip) and re-encode","Workaround: re-encode the source to PNG/JPEG before wrapping it in EncodedImage"],"exampleFix":"// before\n$image = $manager->read($encodedImage); // payload corrupt -> ImageDecoderException\n\n// after: verify the bytes are image data first\n$binary = $encodedImage->toString();\n$mime = finfo_buffer(finfo_open(FILEINFO_MIME_TYPE), $binary);\nif (!str_starts_with((string) $mime, 'image/')) {\n    throw new RuntimeException('EncodedImage payload is not an image, detected: ' . $mime);\n}\n$image = $manager->read($encodedImage);","handlingStrategy":"validation","validationCode":"$binary = $encodedImage->toString();\n$mime = finfo_buffer(finfo_open(FILEINFO_MIME_TYPE), $binary);\nif ($binary === '' || !str_starts_with((string) $mime, 'image/')) {\n    throw new RuntimeException('EncodedImage payload is not image data');\n}","typeGuard":"function isEncodedImage(mixed $value): bool\n{\n    return $value instanceof \\Intervention\\Image\\Interfaces\\EncodedImageInterface;\n}","tryCatchPattern":"try {\n    $image = $manager->read($encodedImage);\n} catch (\\Intervention\\Image\\Exceptions\\ImageDecoderException $e) {\n    // payload undecodable by ImageMagick: log, re-fetch source bytes, or reject upload\n    $logger->error('EncodedImage undecodable: ' . $e->getMessage());\n    throw $e;\n}","preventionTips":["Validate stored binary with finfo_buffer() before wrapping it in EncodedImage","Assert Imagick::queryFormats() contains the formats your pipeline accepts, at deploy time","Keep encoded blobs on disk or use columns large enough to avoid truncation"],"tags":["imagick","decode","encodedimage","binary","unsupported-format"],"backgroundTag":"unsupported-image-format","analyzedSha":"5598b9e39751c34afc5cdee84abef77f92c26f68","analyzedAt":"2026-08-23T02:17:31.068Z","schemaVersion":2},"datasetVersion":"2026-08-23T08:06:27.607Z"}