Alignment and JPEG

This commit is contained in:
moosecrap 2026-07-22 23:02:48 -07:00
parent 48132aa21c
commit d3d0ab9c63

View File

@ -95,7 +95,8 @@ async def handle(args: Dict[str, Any]):
else:
text_w, text_h = len(text) * 8, 15
draw.rectangle([x, y + thumb_size - text_h - 5, x + text_w + 5, y + thumb_size - 2], fill=(0, 0, 0, 180))
# Adjusted black box to align perfectly with the bottom of the image (y + thumb_size)
draw.rectangle([x, y + thumb_size - text_h - 4, x + text_w + 5, y + thumb_size], fill=(0, 0, 0, 180))
draw.text((x + 2, y + thumb_size - text_h - 7), text, fill=(255, 255, 255), font=font)
except Exception as e:
@ -103,7 +104,8 @@ async def handle(args: Dict[str, Any]):
draw.text((x + 5, y + thumb_size // 2), "Error", fill=(255, 0, 0), font=font)
buf = io.BytesIO()
canvas.save(buf, format='PNG')
# Save as JPEG quality 95 to save data
canvas.save(buf, format='JPEG', quality=95)
img_data = base64.b64encode(buf.getvalue()).decode("utf-8")
total_pages = (total_files + PAGE_SIZE - 1) // PAGE_SIZE
@ -129,5 +131,5 @@ async def handle(args: Dict[str, Any]):
return [
{"type": "text", "text": header_text},
{"type": "image", "data": img_data, "mimeType": "image/png"}
{"type": "image", "data": img_data, "mimeType": "image/jpeg"}
]