{"record":{"id":"93aa5950bfc98626","repo":"Intervention/image","slug":"unable-to-find-encoder-by-unknown-origin-file-exte","errorCode":null,"errorMessage":"Unable to find encoder by unknown origin file extension","messagePattern":"Unable to find encoder by unknown origin file extension","errorType":"exception","errorClass":"NotSupportedException","httpStatus":null,"severity":"error","filePath":"src/Encoders/FileExtensionEncoder.php","lineNumber":69,"sourceCode":"        }\n\n        parent::__construct($mediaType, ...$options);\n    }\n\n    /**\n     * {@inheritdoc}\n     *\n     * @see EncoderInterface::encode()\n     *\n     * @throws NotSupportedException\n     * @throws InvalidArgumentException\n     */\n    public function encode(ImageInterface $image): EncodedImageInterface\n    {\n        $extension = is_null($this->extension) ? $image->origin()->fileExtension() : $this->extension;\n\n        if ($extension === null) {\n            throw new NotSupportedException('Unable to find encoder by unknown origin file extension');\n        }\n\n        return $image->encode(\n            $this->encoderByFileExtension(\n                $extension,\n            ),\n        );\n    }\n\n    /**\n     * Create matching encoder for given file extension\n     *\n     * @throws InvalidArgumentException\n     * @throws NotSupportedException\n     */\n    protected function encoderByFileExtension(string|FileExtension $extension): EncoderInterface\n    {\n        if ($extension === '') {","sourceCodeStart":51,"sourceCodeEnd":87,"githubUrl":"https://github.com/Intervention/image/blob/5598b9e39751c34afc5cdee84abef77f92c26f68/src/Encoders/FileExtensionEncoder.php#L51-L87","documentation":"When FileExtensionEncoder is constructed with extension = null, encode() falls back to the extension recorded in the image's Origin: $image->origin()->fileExtension(). Origins built from binary strings, base64 data, or blank images created with ImageManager::create() carry no file extension, so the fallback returns null and encode() throws this NotSupportedException.","triggerScenarios":"Calling $image->encodeUsingFileExtension() (or applying new FileExtensionEncoder(null)) on an image that was read from a binary string, e.g. ImageManager::read(file_get_contents('photo.jpg')), or on an image from ImageManager::create(100, 100), because neither origin records a file extension.","commonSituations":"Processing HTTP uploads via UploadedFile->getContent(), fetching remote images with Guzzle/HTTP clients into strings, storing images as database blobs, or generating new canvases - in all these cases the origin has no file path and therefore no file extension.","solutions":["Pass an explicit extension: $image->encodeUsingFileExtension('png')","Read the image from a file path or SplFileInfo instead of a binary string so the origin records the extension","If the input really is binary, prefer the format-based API: $image->encodeUsingFormat(Format::JPEG) or plain $image->encode() which works from the media type"],"exampleFix":"// before\n$image = $manager->read($request->file('photo')->getContent());\n$image->encodeUsingFileExtension(); // origin has no extension\n\n// after\n$image->encodeUsingFileExtension('webp');","handlingStrategy":"validation","validationCode":"$ext = $image->origin()->fileExtension();\nif ($ext === null || $ext === '') {\n    $ext = 'png'; // binary origins carry no extension\n}\n$image->encodeUsingFileExtension($ext);","typeGuard":null,"tryCatchPattern":"use Intervention\\Image\\Exceptions\\NotSupportedException;\n\ntry {\n    $image->encodeUsingFileExtension();\n} catch (NotSupportedException $e) {\n    $image->encodeUsingFileExtension('png');\n}","preventionTips":["When input is a binary string, always name the target extension explicitly","Prefer reading from file paths or SplFileInfo so the origin records metadata","For 'keep the source format' behavior on binary input use encode(), which resolves by media type"],"tags":["php","intervention-image","encoder","origin","file-extension","not-supported"],"backgroundTag":"unknown-file-extension","analyzedSha":"5598b9e39751c34afc5cdee84abef77f92c26f68","analyzedAt":"2026-08-23T02:17:31.068Z","schemaVersion":2},"datasetVersion":"2026-08-23T08:06:27.607Z"}