整合指南

說明

你可以從瀏覽器、前端或後端直接使用 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