|
|
@ -221,19 +221,18 @@ class PromptServer(): |
|
|
|
with Image.open(file) as img: |
|
|
|
with Image.open(file) as img: |
|
|
|
preview_info = request.rel_url.query['preview'].split(';') |
|
|
|
preview_info = request.rel_url.query['preview'].split(';') |
|
|
|
|
|
|
|
|
|
|
|
if preview_info[0] == "L" or preview_info[0] == "l": |
|
|
|
image_format = preview_info[0] |
|
|
|
img = img.convert("L") |
|
|
|
if image_format not in ['webp', 'jpeg']: |
|
|
|
image_format = preview_info[1] |
|
|
|
image_format = 'webp' |
|
|
|
else: |
|
|
|
|
|
|
|
img = img.convert("RGB") # jpeg doesn't support RGBA |
|
|
|
|
|
|
|
image_format = preview_info[0] |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
quality = 90 |
|
|
|
quality = 90 |
|
|
|
if preview_info[-1].isdigit(): |
|
|
|
if preview_info[-1].isdigit(): |
|
|
|
quality = int(preview_info[-1]) |
|
|
|
quality = int(preview_info[-1]) |
|
|
|
|
|
|
|
|
|
|
|
buffer = BytesIO() |
|
|
|
buffer = BytesIO() |
|
|
|
img.save(buffer, format=image_format, optimize=True, quality=quality) |
|
|
|
if image_format in ['jpeg']: |
|
|
|
|
|
|
|
img = img.convert("RGB") |
|
|
|
|
|
|
|
img.save(buffer, format=image_format, quality=quality) |
|
|
|
buffer.seek(0) |
|
|
|
buffer.seek(0) |
|
|
|
|
|
|
|
|
|
|
|
return web.Response(body=buffer.read(), content_type=f'image/{image_format}', |
|
|
|
return web.Response(body=buffer.read(), content_type=f'image/{image_format}', |
|
|
|