{"record":{"id":"8cd506c15158116f","repo":"Intervention/image","slug":"unable-to-find-encoder-by-unknown-origin-image-for","errorCode":null,"errorMessage":"Unable to find encoder by unknown origin image format","messagePattern":"Unable to find encoder by unknown origin image format","errorType":"exception","errorClass":"NotSupportedException","httpStatus":null,"severity":"error","filePath":"src/Encoders/FormatEncoder.php","lineNumber":42,"sourceCode":"     */\n    public function __construct(protected ?Format $format = null, mixed ...$options)\n    {\n        $this->options = $options;\n    }\n\n    /**\n     * {@inheritdoc}\n     *\n     * @see EncoderInterface::encode()\n     *\n     * @throws NotSupportedException\n     */\n    public function encode(ImageInterface $image): EncodedImageInterface\n    {\n        try {\n            $format = is_null($this->format) ? $image->origin()->format() : $this->format;\n        } catch (NotSupportedException $e) {\n            throw new NotSupportedException('Unable to find encoder by unknown origin image format', previous: $e);\n        }\n\n        return $format->encoder(...$this->options)->encode($image);\n    }\n}\n","sourceCodeStart":24,"sourceCodeEnd":48,"githubUrl":"https://github.com/Intervention/image/blob/5598b9e39751c34afc5cdee84abef77f92c26f68/src/Encoders/FormatEncoder.php#L24-L48","documentation":"FormatEncoder with format = null asks the image origin for its format via $image->origin()->format(). Origins that never recorded a format (blank images from ImageManager::create(), or binary input where no format was attached) make that call throw NotSupportedException, which encode() rethrows wrapped as 'Unable to find encoder by unknown origin image format' with the original as previous.","triggerScenarios":"Applying new FormatEncoder(null) to an image created with ImageManager::create(600, 400), or to an image decoded from a raw binary string whose origin was never assigned a Format.","commonSituations":"Building composites or canvases and then encoding them without naming a target format; pipelines that encode generically ('keep the source format') but receive input whose format metadata is absent.","solutions":["Pass an explicit Format: new FormatEncoder(Format::PNG) or $image->encodeUsingFormat(Format::PNG)","For blank/created images always decide the output format yourself - there is no source format to preserve","For binary input, prefer $image->encode() (AutoEncoder), which resolves via media type instead of origin format"],"exampleFix":"// before\nuse Intervention\\Image\\Encoders\\FormatEncoder;\n$image = $manager->create(1200, 630)->fill('#fff');\n$image->encode(new FormatEncoder(null)); // origin has no format\n\n// after\nuse Intervention\\Image\\Format;\n$image->encodeUsingFormat(Format::PNG);","handlingStrategy":"validation","validationCode":"try {\n    $format = $image->origin()->format();\n} catch (\\Intervention\\Image\\Exceptions\\NotSupportedException $e) {\n    $format = \\Intervention\\Image\\Format::PNG; // created/binary images have no origin format\n}\n$image->encodeUsingFormat($format);","typeGuard":null,"tryCatchPattern":"use Intervention\\Image\\Exceptions\\NotSupportedException;\n\ntry {\n    $image->encode(new FormatEncoder(null));\n} catch (NotSupportedException $e) {\n    $image->encodeUsingFormat(\\Intervention\\Image\\Format::PNG);\n}","preventionTips":["For images from create() always specify the target format explicitly","Do not assume origin()->format() exists for binary-string input","Use encode() (AutoEncoder) when you want automatic format resolution"],"tags":["php","intervention-image","encoder","origin","format","not-supported"],"backgroundTag":"unknown-image-format","analyzedSha":"5598b9e39751c34afc5cdee84abef77f92c26f68","analyzedAt":"2026-08-23T02:17:31.068Z","schemaVersion":2},"datasetVersion":"2026-08-23T08:06:27.607Z"}