扩展《丑丑头像生成器》,支持 api 调用,并且固定返回值

37次阅读

共计 761 个字符,预计需要花费 2 分钟才能阅读完成。

声明

本文的头像生成部分参考了项目 txstc55/ugly-avatar

背景

在浏览社区论坛时,我注意到许多相似的头像,它们虽然并不美观,但却具有鲜明的特点。通过查阅评论,我发现这些头像都是由一个开源的头像生成工具制作的。

效果展示

![转存失败,建议直接上传图片文件](https://github.com/mamumu123/picx-images-hosting/raw/master/ 截屏 2024-05-20-15.44.50.5mnmsiwu1r.webp)

体验地址

demo 体验地址

源码地址

github 地址

项目介绍

做了哪些优化

  • 增设了 API 接口,可以直接返回随机生成的头像;
  • 添加了 ‘id’ 和 ‘username’ 参数,通过固定这两个参数,可以确保返回的头像保持一致;
  • 增加了 ‘bg_color’ 参数,通过这个参数,可以确保头像的背景色是固定的颜色值;
  • 增加了 ‘w’ 和 ‘h’ 参数,通过这个参数,可以指定返回图片的宽度和高度;

api demo

随机返回

https://next-api-share.vercel.app/api/face

固定背景色

https://next-api-share.vercel.app/api/face?bg_color=rgb(245,245,220)

https://next-api-share.vercel.app/api/face?bg_color=red

固定返回值

https://next-api-share.vercel.app/api/face?id=666

https://next-api-share.vercel.app/api/face?username=john

固定宽度或高度

https://next-api-share.vercel.app/api/face?w=400&h=400

正文完
 0