t
All checks were successful
Deploy WebSocket Server / deploy (push) Successful in 21s

This commit is contained in:
jeremygan2021
2026-03-05 22:19:48 +08:00
parent e728cd1075
commit c9550f8a0d
2 changed files with 24 additions and 5 deletions

View File

@@ -275,7 +275,10 @@ async def send_image_to_client(websocket: WebSocket, image_path: str):
print(f"Sending image to ESP32, size: {len(image_data)} bytes")
# Send start marker
await websocket.send_text(f"IMAGE_START:{len(image_data)}:{THUMB_SIZE}")
model_name = f"{image_generator.provider}"
if image_generator.model:
model_name += f" {image_generator.model}"
await websocket.send_text(f"IMAGE_START:{len(image_data)}:{THUMB_SIZE}:{model_name}")
# Send binary data directly
chunk_size = 512 # Decreased chunk size for ESP32 memory stability
@@ -594,8 +597,23 @@ 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)
# 保持比例缩放
# Calculate aspect ratio
ratio = min(THUMB_SIZE / img.width, THUMB_SIZE / img.height)
new_width = int(img.width * ratio)
new_height = int(img.height * ratio)
resized_img = img.resize((new_width, new_height), Image.LANCZOS)
# Create black background
final_img = Image.new("RGB", (THUMB_SIZE, THUMB_SIZE), (0, 0, 0))
# Paste centered
x_offset = (THUMB_SIZE - new_width) // 2
y_offset = (THUMB_SIZE - new_height) // 2
final_img.paste(resized_img, (x_offset, y_offset))
img = final_img
# 转换为RGB565格式的原始数据
# 每个像素2字节 (R5 G6 B5)