printer
All checks were successful
Deploy WebSocket Server / deploy (push) Successful in 19s

This commit is contained in:
jeremygan2021
2026-03-05 20:36:13 +08:00
parent ea0594bf88
commit 409b69b633
2 changed files with 17 additions and 22 deletions

View File

@@ -676,8 +676,17 @@ def generate_image(prompt, progress_callback=None, retry_count=0, max_retries=2)
from PIL import Image
img = Image.open(GENERATED_IMAGE_FILE)
# 缩小到THUMB_SIZE x THUMB_SIZE
img = img.resize((THUMB_SIZE, THUMB_SIZE), Image.LANCZOS)
# 缩小到THUMB_SIZE x THUMB_SIZE,保持比例并居中(防止拉伸)
img.thumbnail((THUMB_SIZE, THUMB_SIZE), Image.LANCZOS)
# 创建黑色背景 (240x240)
bg = Image.new("RGB", (THUMB_SIZE, THUMB_SIZE), (0, 0, 0))
# 计算居中位置
left = (THUMB_SIZE - img.width) // 2
top = (THUMB_SIZE - img.height) // 2
bg.paste(img, (left, top))
img = bg
# 转换为RGB565格式的原始数据
# 每个像素2字节 (R5 G6 B5)