集成指南

帮助

你可以从浏览器、前端或后端直接使用 hashavatar.app。每个头像 URL 都是确定性的,因此相同的标识符和选项始终会产生相同结果。

基础 URL

当你需要简单的公开图片 URL 时,请使用查询端点。

https://hashavatar.app/v1/[email protected]&algorithm=sha512&kind=robot&background=white&accessory=glasses&color=gold&expression=happy&shape=circle&format=webp&size=256

路径式 URL

如果你更喜欢更整洁的嵌入 URL,可以使用路径形式。

https://hashavatar.app/avatar/fox/[email protected]/webp

HTML 示例

<img
  src="https://hashavatar.app/v1/[email protected]&algorithm=sha512&kind=monster&background=themed&accessory=horns&color=crimson&expression=grumpy&shape=hexagon&format=webp&size=256"
  alt="Generated monster avatar"
/>

JavaScript 示例

const avatarUrl = new URL("https://hashavatar.app/v1/avatar");
avatarUrl.search = new URLSearchParams({
  id: user.email,
  algorithm: "sha512",
  kind: "robot",
  background: "white",
  accessory: "glasses",
  color: "gold",
  expression: "happy",
  shape: "circle",
  format: "webp",
  size: "256",
}).toString();

支持的参数

  • id: any stable identifier such as an email, username, internal user id, or one-way hash
  • tenant: optional namespace partition for multi-tenant apps
  • style_version: optional style namespace such as v2
  • algorithm: identity hash mode; only sha512 is supported
  • kind: any public hashavatar family, including cat, dog, robot, planet, rocket, frog, panda, cupcake, pizza, octopus, knight, bear, penguin, dragon, ninja, astronaut, diamond, coffee-cup, and shield
  • background: themed, white, black, dark, light, transparent, polka-dot, striped, checkerboard, grid, sunrise, ocean, or starry
  • accessory: none, glasses, hat, headphones, crown, bowtie, eyepatch, scarf, halo, or horns
  • color: default, neon-mint, pastel-pink, crimson, gold, or deep-sea-blue
  • expression: default, happy, grumpy, surprised, sleepy, winking, cool, or crying
  • shape: square, circle, squircle, hexagon, or octagon
  • format: output format; only webp is supported
  • size: from 64 up to 1024

配饰和表情图层适用于角色风格的家族。planet、rocket、paws、mushroom、cactus、cupcake、pizza、icecream、diamond、coffee-cup 和 shield 等物体风格家族会被规范化为 accessory=none 和 expression=default。

签名存储链接

如果此部署配置了对象存储,可以从 /v1/avatar/link 请求预签名存储链接。该端点会存储生成的对象,并返回包含签名 URL、对象键和哈希缓存键的 JSON。标准头像响应不会在响应头中暴露签名链接元数据。

GET https://hashavatar.app/v1/avatar/[email protected]&algorithm=sha512&kind=robot&background=white&accessory=glasses&color=gold&expression=happy&shape=circle&format=webp&size=256

开源

公开视频站点源码位于 API 代码库中,可复用头像渲染器发布在 crates.io。 代码库 · crates.io