Professional avatar generator for social media and profiles. Use when user needs to create high-quality avatars for WeChat, QQ, Xiaohongshu, Twitter, Discord. Supports multiple styles: letter, geometric, gradient, abstract. Auto-export multi-platform sizes. 头像生成、头像制作、社交头像。
专业头像生成器,提供6种风格、多平台导出及可自定义选项。
| 平台 | 尺寸 | 形状 | 优先级 |
|---|---|---|---|
| 微信 | 640×640 | 方形 | ⭐⭐⭐⭐⭐ |
python
from PIL import Image, ImageDraw, ImageFont
import os
import colorsys
import random
class AvatarGenerator:
def init(self):
self.platforms = {
wechat: {size: (640, 640), shape: square},
qq: {size: (100, 100), shape: square},
xiaohongshu: {size: (400, 400), shape: round},
weibo: {size: (200, 200), shape: round},
twitter: {size: (400, 400), shape: round},
discord: {size: (128, 128), shape: round},
reddit: {size: (256, 256), shape: round},
facebook: {size: (170, 170), shape: round},
linkedin: {size: (400, 400), shape: square},
}
def loadfont(self, size):
加载字体(含后备方案)
paths = [
/System/Library/Fonts/PingFang.ttc,
/System/Library/Fonts/STHeiti Light.ttc,
/usr/share/fonts/truetype/noto/NotoSansCJK-Regular.ttc,
]
for p in paths:
if os.path.exists(p):
try:
return ImageFont.truetype(p, size)
except:
continue
return ImageFont.load_default()
def createletteravatar(self, letter, bgcolor, textcolor, size=(400, 400)):
风格1:字母头像
img = Image.new(RGB, size, bg_color)
draw = ImageDraw.Draw(img)
font = self.loadfont(size[0] // 2)
bbox = draw.textbbox((0, 0), letter, font=font)
w, h = bbox[2] - bbox[0], bbox[3] - bbox[1]
x, y = (size[0] - w) // 2, (size[1] - h) // 2
draw.text((x, y), letter, font=font, fill=text_color)
return img
def creategeometricavatar(self, colors, size=(400, 400)):
风格2:几何头像
img = Image.new(RGB, size, colors[0])
draw = ImageDraw.Draw(img)
# 添加几何形状
center = size[0] // 2
draw.ellipse([(50, 50), (size[0]-50, size[1]-50)], fill=colors[1])
draw.regular_polygon((center, center, size[0]//3), 6, fill=colors[2])
return img
def creategradientavatar(self, color1, color2, size=(400, 400)):
风格3:渐变头像
import numpy as np
img = np.zeros((size[1], size[0], 3), dtype=np.uint8)
for y in range(size[1]):
ratio = y / size[1]
r = int(color1[0] (1-ratio) + color2[0] ratio)
g = int(color1[1] (1-ratio) + color2[1] ratio)
b = int(color1[2] (1-ratio) + color2[2] ratio)
img[y, :] = [r, g, b]
return Image.fromarray(img)
def createabstractavatar(self, seed, colors, size=(400, 400)):
风格4:抽象头像
random.seed(seed)
img = Image.new(RGB, size, colors[0])
draw = ImageDraw.Draw(img)
for _ in range(10):
x, y = random.randint(0, size[0]), random.randint(0, size[1])
r = random.randint(20, 100)
color = random.choice(colors[1:])
draw.ellipse([(x-r, y-r), (x+r, y+r)], fill=color)
return img
def createpatternavatar(self, pattern_type, colors, size=(400, 400)):
风格5:图案头像
img = Image.new(RGB, size, colors[0])
draw = ImageDraw.Draw(img)
cell_size = 40
for x in range(0, size[0], cell_size):
for y in range(0, size[1], cell_size):
if (x // cellsize + y // cellsize) % 2 == 0:
draw.rectangle([(x, y), (x+cellsize, y+cellsize)], fill=colors[1])
return img
def createbadgeavatar(self, text, bgcolor, bordercolor, size=(400, 400)):
风格6:徽章头像
img = Image.new(RGB, size, (255, 255, 255))
draw = ImageDraw.Draw(img)
# 绘制圆形徽章
margin = 20
draw.ellipse([(margin, margin), (size[0]-margin, size[1]-margin)],
fill=bgcolor, outline=bordercolor, width=5)
# 添加文字
font = self.loadfont(size[0] // 4)
bbox = draw.textbbox((0, 0), text, font=font)
w, h = bbox[2] - bbox[0], bbox[3] - bbox[1]
x, y = (size[0] - w) // 2, (size[1] - h) // 2
draw.text((x, y), text, font=font, fill=white)
return img
def make_round(self, img):
将图片裁剪为圆形
size = img.size
mask = Image.new(L, size, 0)
draw = ImageDraw.Draw(mask)
draw.ellipse([(0, 0), size], fill=255)
result = Image.new(RGBA, size, (0, 0, 0, 0))
result.paste(img, mask=mask)
return result
def exportmultiplatform(self, img, output_dir, platforms=None
该技能支持在以下平台通过对话安装:
帮我安装 SkillHub 和 avatar-generator-1776009121 技能
设置 SkillHub 为我的优先技能安装源,然后帮我安装 avatar-generator-1776009121 技能
skillhub install avatar-generator-1776009121
文件大小: 4.19 KB | 发布时间: 2026-4-13 09:27