Acly / comfyui-tooling-nodes

Nodes for using ComfyUI as a backend for external tools. Send and receive images directly without filesystem upload/download.
GNU General Public License v3.0
319 stars 39 forks source link

sending as octet-stream #19

Open Sam-Hoult opened 1 month ago

Sam-Hoult commented 1 month ago

I was struggling with this for a while to get the base64 image to show. I ended up having to change the send_images https://github.com/Acly/comfyui-tooling-nodes/blob/ef5ccfa98f035fd1d9fd00a21ac4ab75a5f73061/nodes.py#L69 to

    def send_images(self, images, format):
        results = []
        for tensor in images:
            array = 255.0 * tensor.cpu().numpy()
            image = Image.fromarray(np.clip(array, 0, 255).astype(np.uint8))

            # Convert image to bytes
            buffered = BytesIO()
            image.save(buffered, format=format)
            img_str = base64.b64encode(buffered.getvalue()).decode()

            server = PromptServer.instance
            server.send_sync(
                BinaryEventTypes.PREVIEW_IMAGE,  # Changed from UNENCODED_PREVIEW_IMAGE
                img_str,
                server.client_id,
            )
            results.append(
                {"source": "websocket", "content-type": f"image/{format.lower()};base64", "type": "output"}
            )

        return {"ui": {"images": results}

This was changed with AI so I'm not totally sure.

Acly commented 1 month ago

It's not intended to send base64. I'm not sure what the use of that would be?