mirror of
https://github.com/invoke-ai/InvokeAI
synced 2024-08-30 20:32:17 +00:00
perf(invoke_ai_web_server): encode intermediate result previews as jpeg (#2817)
For size savings of about 80%, and jpeg encoding is still plenty fast.
This commit is contained in:
commit
6e0c6d9cc9
@ -1062,7 +1062,7 @@ class InvokeAIWebServer:
|
|||||||
(width, height) = image.size
|
(width, height) = image.size
|
||||||
width *= 8
|
width *= 8
|
||||||
height *= 8
|
height *= 8
|
||||||
img_base64 = image_to_dataURL(image)
|
img_base64 = image_to_dataURL(image, image_format="JPEG")
|
||||||
self.socketio.emit(
|
self.socketio.emit(
|
||||||
"intermediateResult",
|
"intermediateResult",
|
||||||
{
|
{
|
||||||
@ -1714,13 +1714,14 @@ def dataURL_to_image(dataURL: str) -> ImageType:
|
|||||||
return image
|
return image
|
||||||
|
|
||||||
|
|
||||||
def image_to_dataURL(image: ImageType) -> str:
|
def image_to_dataURL(image: ImageType, image_format:str="PNG") -> str:
|
||||||
"""
|
"""
|
||||||
Converts an image into a base64 image dataURL.
|
Converts an image into a base64 image dataURL.
|
||||||
"""
|
"""
|
||||||
buffered = io.BytesIO()
|
buffered = io.BytesIO()
|
||||||
image.save(buffered, format="PNG")
|
image.save(buffered, format=image_format)
|
||||||
image_base64 = "data:image/png;base64," + base64.b64encode(
|
mime_type = Image.MIME.get(image_format.upper(), "image/" + image_format.lower())
|
||||||
|
image_base64 = f"data:{mime_type};base64," + base64.b64encode(
|
||||||
buffered.getvalue()
|
buffered.getvalue()
|
||||||
).decode("UTF-8")
|
).decode("UTF-8")
|
||||||
return image_base64
|
return image_base64
|
||||||
|
Loading…
Reference in New Issue
Block a user