webui: chat rendering refactor + image_read PNG compression

This commit is contained in:
Levi Neely 2026-05-25 23:13:03 +02:00
parent 0eb6cad285
commit 84f5d26d60
2 changed files with 20 additions and 1 deletions

View File

@ -35,6 +35,25 @@ if not mime:
with open(file_path, 'rb') as f:
data = f.read()
MAX_SIZE = 128 * 1024
if mime == 'image/png' and len(data) > MAX_SIZE:
from PIL import Image
import io
img = Image.open(io.BytesIO(data))
# progressively scale down until under budget
for scale in [1.0, 0.75, 0.5, 0.35, 0.25]:
buf = io.BytesIO()
if scale < 1.0:
new_size = (int(img.width * scale), int(img.height * scale))
resized = img.resize(new_size, Image.LANCZOS)
else:
resized = img
resized.save(buf, format='PNG', optimize=True)
data = buf.getvalue()
if len(data) <= MAX_SIZE:
break
b64 = base64.b64encode(data).decode('ascii')
print(json.dumps({"isError": False, "content": [

2
webui

@ -1 +1 @@
Subproject commit 6d21f142afda6f870556229e4acfdbb2c5fbfdc4
Subproject commit aa0e99213dffc26c8ebb54b13946afefbc205b29