Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Send Image (WebSocket) #2

Closed
olegchomp opened this issue Nov 5, 2023 · 2 comments
Closed

Send Image (WebSocket) #2

olegchomp opened this issue Nov 5, 2023 · 2 comments

Comments

@olegchomp
Copy link

Hi! Can you provide code example for decoding image?

@Acly
Copy link
Owner

Acly commented Nov 6, 2023

I'm using python code like this:

async for msg in websocket:
    if isinstance(msg, bytes):
        s = struct.calcsize(">II")
        data = memoryview(msg)
        if len(data) > s:
            event, format = struct.unpack_from(">II", data)            
            if event == 1 and format == 2: # 1=PREVIEW_IMAGE, 2=PNG, see ComfyUI server.py
                return Image.png_from_bytes(data[s:])

where Image.png_from_bytes does QImage.fromData(data, "PNG") because I use Qt anyway, but you can use similar method with eg. PIL.Image.open

@olegchomp
Copy link
Author

Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants