คู่มือการผสานรวม

ช่วยเหลือ

ใช้ hashavatar.app ได้โดยตรงจากเบราว์เซอร์ frontend หรือ backend ของคุณ ทุก URL อวาตาร์ให้ผลแบบกำหนดได้ ดังนั้นตัวระบุและตัวเลือกเดียวกันจะให้ผลลัพธ์เดียวกันเสมอ

URL พื้นฐาน

ใช้ endpoint แบบ query เมื่อคุณต้องการ 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 แบบ path

ใช้รูปแบบ path หากคุณต้องการ 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 จะถูก normalize เป็น accessory=none และ expression=default

ลิงก์ storage ที่ลงนาม

หาก deployment นี้ตั้งค่า object storage แล้ว ให้ขอลิงก์ storage แบบ presigned จาก /v1/avatar/link endpoint นี้จะเก็บ object ที่สร้างและคืน JSON พร้อม URL ที่ลงนาม object key และ cache key ที่ hash แล้ว คำตอบอวาตาร์มาตรฐานจะไม่เปิดเผย metadata ของลิงก์ที่ลงนามใน response header

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 repository และ renderer อวาตาร์ที่นำกลับมาใช้ได้เผยแพร่บน crates.io รีโพซิทอรี · crates.io