Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions invokeai/backend/invoke_ai_web_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -1062,7 +1062,7 @@ def image_progress(sample, step):
(width, height) = image.size
width *= 8
height *= 8
img_base64 = image_to_dataURL(image)
img_base64 = image_to_dataURL(image, image_format="JPEG")
self.socketio.emit(
"intermediateResult",
{
Expand Down Expand Up @@ -1714,13 +1714,14 @@ def dataURL_to_image(dataURL: str) -> ImageType:
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.
"""
buffered = io.BytesIO()
image.save(buffered, format="PNG")
image_base64 = "data:image/png;base64," + base64.b64encode(
image.save(buffered, format=image_format)
mime_type = Image.MIME.get(image_format.upper(), "image/" + image_format.lower())
image_base64 = f"data:{mime_type};base64," + base64.b64encode(
buffered.getvalue()
).decode("UTF-8")
return image_base64
Expand Down