> [!NOTE] > 本文档由 WeHub 基于上游 README 翻译整理,属于社区翻译,非官方中文文档。 > [English](./README.en.md) · [原始项目](https://github.com/dicebear/dicebear) · [上游 README](https://github.com/dicebear/dicebear/blob/HEAD/README.md) > 原作者、版权与许可证归属以原始项目及本仓库 LICENSE 文件为准。

DiceBear 头像库

DiceBear 是一款开源头像库。它可将任意种子字符串(例如用户名或电子邮件地址)转换为 35 种以上、由不同艺术家设计的风格之一的 SVG 头像。相同种子始终生成相同头像,因此你可以存储字符串而非图片,也无需让用户上传个人资料照片。 可通过风格选项自定义头像:颜色、背景、旋转,以及发型、眼镜等个别特征。 [Playground](https://www.dicebear.com/playground) | [Documentation](https://www.dicebear.com/introduction) | [Editor](https://editor.dicebear.com) ## 一个库,六种语言 DiceBear 10 以 JavaScript、PHP、Python、Rust、Go 和 Dart 的原生库形式发布。每个移植版本都通过共享测试套件,要求 SVG 输出与 JavaScript 参考实现字节级一致。在浏览器中生成头像,稍后在 Go 或 PHP 后端重新生成,你会得到相同的字节。 | 语言 | 包 | 安装 | | ----------------------- | ----------------------------------------------------------------------- | -------------------------------------------- | | JavaScript / TypeScript | [`@dicebear/core`](https://www.npmjs.com/package/@dicebear/core) | `npm install @dicebear/core` | | PHP | [`dicebear/core`](https://packagist.org/packages/dicebear/core) | `composer require dicebear/core` | | Python | [`dicebear-core`](https://pypi.org/project/dicebear-core/) | `pip install dicebear-core` | | Rust | [`dicebear-core`](https://crates.io/crates/dicebear-core) | `cargo add dicebear-core` | | Go | [`dicebear-go`](https://pkg.go.dev/github.com/dicebear/dicebear-go/v10) | `go get github.com/dicebear/dicebear-go/v10` | | Dart | [`dicebear_core`](https://pub.dev/packages/dicebear_core) | `dart pub add dicebear_core` | 在 JavaScript 中用法如下;[documentation](https://www.dicebear.com/introduction) 中有各语言的等价写法: ```js import { Avatar } from '@dicebear/core'; import definition from '@dicebear/styles/lorelei.json' with { type: 'json' }; const avatar = new Avatar(definition, { seed: 'John Doe', size: 128, }); avatar.toString(); // SVG string avatar.toDataUri(); // data:image/svg+xml;charset=utf-8,... ``` 35 种以上的头像风格是来自 [`dicebear/styles`](https://github.com/dicebear/styles) 仓库的普通 JSON 定义,每种语言都有对应的包。你也可以使用 Figma 或从零开始 [create your own style](https://www.dicebear.com/guides/create-an-avatar-style-with-figma/),。 ## 无需编写代码 - [HTTP API](https://www.dicebear.com/how-to-use/http-api/) 可通过普通 URL 返回头像,免费且无需账户:`https://api.dicebear.com/10.x/lorelei/svg?seed=Felix`。如需完全控制和隐私保护,你可以用单个 Docker 容器 [host it yourself](https://www.dicebear.com/guides/host-the-http-api-yourself/)。 - [CLI](https://www.dicebear.com/how-to-use/cli/) 可批量生成头像文件:`npx dicebear lorelei --count 10`。 - [editor](https://editor.dicebear.com) 可让你手动组装单个头像并导出。 ## 本仓库 本 monorepo 包含六个核心库、CLI、SVG 转栅格转换器、文档站点([dicebear.com](https://www.dicebear.com)),)以及编辑器。相关项目位于各自的仓库中: - [`dicebear/styles`](https://github.com/dicebear/styles): 官方头像风格定义 - [`dicebear/schema`](https://github.com/dicebear/schema): 定义与选项背后的 JSON Schema - [`dicebear/api`](https://github.com/dicebear/api): 可自托管的 HTTP API - [`dicebear/exporter-plugin-for-figma`](https://github.com/dicebear/exporter-plugin-for-figma): 供风格作者使用的 Figma 插件 欢迎贡献;[CONTRIBUTING.md](./CONTRIBUTING.md) 说明了环境配置以及各类变更应归属的位置。 ## 许可证 代码采用 [MIT licensed](./LICENSE),包括商业用途。头像风格是各位艺术家的作品,并附带各自的许可证;[license overview](https://www.dicebear.com/licenses/) 列出了全部内容,许多仅要求署名。 ## 赞助方 Advertisement: 非常感谢为我们提供免费或折扣产品的赞助方。 bunny.net