{"record":{"id":"8d32a24bdc8e0e87","repo":"Intervention/image","slug":"unable-to-find-encoder-for-unknown-image-file-exte","errorCode":null,"errorMessage":"Unable to find encoder for unknown image file extension \"' . $extension . '\"","messagePattern":"Unable to find encoder for unknown image file extension \"' \\. \\$extension \\. '\"","errorType":"exception","errorClass":"NotSupportedException","httpStatus":null,"severity":"error","filePath":"src/Encoders/FileExtensionEncoder.php","lineNumber":94,"sourceCode":"        );\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 === '') {\n            throw new InvalidArgumentException('Argument $extension must not be an empty string');\n        }\n\n        try {\n            $extension = is_string($extension) ? FileExtension::from(strtolower($extension)) : $extension;\n        } catch (Error) {\n            throw new NotSupportedException(\n                'Unable to find encoder for unknown image file extension \"' . $extension . '\"',\n            );\n        }\n\n        return $extension->format()->encoder(...$this->options);\n    }\n}\n","sourceCodeStart":76,"sourceCodeEnd":102,"githubUrl":"https://github.com/Intervention/image/blob/5598b9e39751c34afc5cdee84abef77f92c26f68/src/Encoders/FileExtensionEncoder.php#L76-L102","documentation":"The runtime sibling of the constructor check: encoderByFileExtension() calls FileExtension::from(strtolower($extension)) and converts the enum's ValueError into this NotSupportedException when the value matches no FileExtension case. Unlike the constructor check, this one also fires for extensions that arrive indirectly, e.g. extracted from a save path by FilePathEncoder or returned by the image origin.","triggerScenarios":"Calling $image->save('output.svg') or $image->encodeUsingPath('/tmp/out.tga') - FilePathEncoder extracts the extension from the path and hands it to encoderByFileExtension(), which cannot map it. Also fired when origin()->fileExtension() returns an unsupported non-empty value.","commonSituations":"Saving under a filename whose extension names a format the library cannot encode (svg, pdf, psd); writing thumbnails with exotic extensions; user-supplied output filenames trusted verbatim.","solutions":["Save under an extension the library supports: jpg, jpeg, pjpg, pjpeg, png, gif, webp, avif, bmp, tif, tiff, jp2, j2k, jp2k, jpf, jpm, jpg2, j2c, jpc, jpx, heic, heif, jxl, ico","If you must keep the original filename, encode explicitly by format: $image->encodeUsingFormat(Format::PNG)->save('output.svg') is also wrong - instead pick the encoder first and write the bytes yourself with file_put_contents()","Validate output filenames from users against FileExtension::tryFrom() before calling save()"],"exampleFix":"// before\n$image->save('uploads/' . $userChosenName); // 'avatar.svg' -> unknown extension\n\n// after\n$ext = strtolower(pathinfo($userChosenName, PATHINFO_EXTENSION));\n$safe = FileExtension::tryFrom($ext) ? $userChosenName : 'avatar.png';\n$image->save('uploads/' . $safe);","handlingStrategy":"type-guard","validationCode":"use Intervention\\Image\\FileExtension;\n\n$pathExt = strtolower(pathinfo($path, PATHINFO_EXTENSION));\nif (FileExtension::tryFrom($pathExt) === null) {\n    throw new RuntimeException('Output format not supported: ' . $pathExt);\n}\n$image->save($path);","typeGuard":"use Intervention\\Image\\FileExtension;\n\nfunction pathHasSupportedExtension(string $path): bool\n{\n    $ext = strtolower(pathinfo($path, PATHINFO_EXTENSION));\n\n    return $ext !== '' && FileExtension::tryFrom($ext) !== null;\n}","tryCatchPattern":"use Intervention\\Image\\Exceptions\\NotSupportedException;\n\ntry {\n    $image->save($path);\n} catch (NotSupportedException $e) {\n    // extension names a format the library cannot encode; pick explicitly\n    file_put_contents($path, (string) $image->encodeUsingFormat(\\Intervention\\Image\\Format::PNG));\n}","preventionTips":["Constrain output filenames to a fixed set of supported extensions","Validate user-chosen filenames before passing them to save()","Remember Image::save() falls back to MediaTypeEncoder only for EncoderException, not for NotSupportedException"],"tags":["php","intervention-image","encoder","file-extension","save","not-supported"],"backgroundTag":"unsupported-file-format","analyzedSha":"5598b9e39751c34afc5cdee84abef77f92c26f68","analyzedAt":"2026-08-23T02:17:31.068Z","schemaVersion":2},"datasetVersion":"2026-08-23T08:06:27.607Z"}