This commit is contained in:
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user