# DiceBear: 开源头像库与 API ## 什么是 DiceBear? DiceBear 为你的项目生成头像。头像风格涵盖了多种外观,从抽象图形到设计角色,这些头像可用于多种类型的应用程序。 除了纯随机头像之外,你还可以为用户身份创建[确定性](https://en.wikipedia.org/wiki/Deterministic_algorithm)头像。借助内置的[PRNG](https://en.wikipedia.org/wiki/Pseudorandom_number_generator),你可以基于一个种子一次又一次生成相同的头像。你也可以进行个性化调整:每种头像风格都提供了许多选项来微调结果。 DiceBear 可通过 [JavaScript 库](https://dicebear.zhcndoc.com/how-to-use/js-library/)、 [PHP 库](https://dicebear.zhcndoc.com/how-to-use/php-library/)、 [Python 库](https://dicebear.zhcndoc.com/how-to-use/python-library/)、 [Rust 库](https://dicebear.zhcndoc.com/how-to-use/rust-library/)、 [Go 库](https://dicebear.zhcndoc.com/how-to-use/go-library/)、 [Dart 库](https://dicebear.zhcndoc.com/how-to-use/dart-library/)、[HTTP API](https://dicebear.zhcndoc.com/how-to-use/http-api/)、 [CLI](https://dicebear.zhcndoc.com/how-to-use/cli/)、 [Figma 插件](https://www.figma.com/community/plugin/1005765655729342787/DiceBear-Exporter)、 [编辑器](https://editor.dicebear.com) 和 [Playground](https://dicebear.zhcndoc.com/playground/) 使用,因此你可以 将其集成到大多数项目中。[头像 API](https://dicebear.zhcndoc.com/how-to-use/http-api/) 提供基于 URL 的集成方式,无需安装任何内容。 ## 如何使用? ## 它是如何工作的? 这些头像以 [SVG](https://en.wikipedia.org/wiki/Scalable_Vector_Graphics) 格式创建。 这使得无需太多计算资源即可动态生成头像。在大多数情况下, 会从一组 SVG 元素中选择各种元素,例如头发、眼睛、耳朵等,并将它们组合起来创建一个角色 / 头像。 [FNV-1a](https://en.wikipedia.org/wiki/Fowler%E2%80%93Noll%E2%80%93Vo_hash_function) 结合 [Mulberry32](https://gist.github.com/tommyettinger/46a874533244883189143505d203312c) 被用作 [PRNG](https://en.wikipedia.org/wiki/Pseudorandom_number_generator) 的算法。该 PRNG **不会**尝试成为 [加密安全的](https://en.wikipedia.org/wiki/Cryptographically-secure_pseudorandom_number_generator)。 ## 设计即隐私 DiceBear 在构建时就将隐私放在首位。使用 [JavaScript 库](https://dicebear.zhcndoc.com/how-to-use/js-library/), [PHP 库](https://dicebear.zhcndoc.com/how-to-use/php-library/), [Python 库](https://dicebear.zhcndoc.com/how-to-use/python-library/), [Rust 库](https://dicebear.zhcndoc.com/how-to-use/rust-library/), [Go 库](https://dicebear.zhcndoc.com/how-to-use/go-library/) 或 [Dart 库](https://dicebear.zhcndoc.com/how-to-use/dart-library/) 时,头像完全在您的基础设施上生成。任何个人数据都不会离开您的系统。对于需要对数据保留和基础设施进行完全控制的团队,DiceBear 可以进行 [自托管](https://dicebear.zhcndoc.com/guides/host-the-http-api-yourself/),因此无需依赖外部服务。