Nodes/ComfyUI-SimpleUtils/Image > Base64ToImage
ComfyUI Node

Image > Base64ToImage

Someone handed you a wall of text, and it's a picture — Base64ToImage

By moonstar-x-libs·Created 22 days ago·Updated 12 days ago· 1
Image > Base64ToImage
    • IMAGE
    ◄base64—►

    Base64 is what an image looks like when it has to travel through text

    Everything outside ComfyUI that touches an image seems to insist on text. A JSON API response, a database column, a webhook payload, a chat message, a workflow JSON someone pasted on a forum - all of those carry pictures as base64. Inside ComfyUI there is no such thing as a base64 image: an IMAGE is a tensor. This node is the door between the two.

    You reach for it the moment the pixels arrive as a string instead of a file. Some image APIs answer with a b64_json field rather than a URL. A scraper or bot writes the bytes into a log or a database row. Somebody shares a workflow with the reference image tucked inside the JSON, so it doesn't depend on a path in their ComfyUI/input folder. Text in hand, graph wanted - that's the whole pitch.

    What it actually does

    Read the source and the whole thing is four steps: decode the base64, wrap the bytes in a BytesIO, hand that to Pillow, convert to RGB if it isn't already RGB, then divide by 255 into a float32 numpy array and add the batch dimension. The output is a (1, H, W, 3) float tensor with values from 0 to 1 - precisely the shape every IMAGE socket in ComfyUI expects. Any format Pillow can open works: PNG, JPEG, WebP, BMP, GIF (you get its first frame, not an animation).

    The one input and the one output

    • base64 - a multiline STRING. The author's own tooltip: "The base64 string to transform." Raw base64 only, which matters a lot; see below. You can paste into the box, or right-click it and choose Convert Widget to Input so you can wire it from another node's string output.
    • IMAGE - a batch containing exactly one image. Wire it wherever an image goes: VAE Encode, a ControlNet preprocessor, an upscaler, a mask, a save.

    One thing that catches beginners: this node shows you nothing. It has no preview and no UI output, so if you queue a graph where the decoded image goes nowhere, it runs, succeeds, and the canvas stays empty. Plug the IMAGE into Preview Image or Save Image to actually see it.

    Installing it

    The whole pack is on the Comfy Registry, so ComfyUI Manager is the easy path: open Manager, search ComfyUI-SimpleUtils, install, restart. The Comfy CLI does the same thing:

    comfy node install comfyui-simpleutils
    

    Manual, if you'd rather see the code:

    cd ComfyUI/custom_nodes
    git clone https://github.com/moonstar-x-libs/ComfyUI-SimpleUtils.git
    # restart ComfyUI
    

    No models to download and no heavy dependencies to fight - the only imports are numpy, pillow and torch, all of which ComfyUI already ships. Both nodes land under the SimpleUtils category, named Image > Base64ToImage and Image > ImageToBase64. The pack publishes to the Comfy Registry on release, which is why Manager finds it; it's young, so treat the node list as growing rather than final.

    Where it bites

    The data: prefix. data:image/png;base64,iVBORw0K... will not work. The README says raw base64, and the reason it can't be lenient is that base64.b64decode silently discards characters outside the alphabet - but the letters inside dataimagepngbase64 are in the alphabet, so a prefix doesn't get harmlessly skipped, it gets decoded as garbage and usually blows up on padding. Strip the prefix wherever the string came from.

    binascii.Error: Invalid base64-encoded string means the string is truncated or isn't base64 at all. A copy-paste out of a chat window that cut off mid-line is the classic cause.

    PIL.UnidentifiedImageError: cannot identify image file means it decoded fine but the bytes aren't an image. Nine times out of ten you base64'd an API error response instead of an image. Cheap sanity check before blaming the node:

    import base64
    print(base64.b64decode(your_string)[:120])
    

    Alpha disappears. Anything that isn't RGB is converted to RGB, so a transparent PNG comes back opaque, showing whatever colours were sitting underneath the transparency - usually black. If alpha matters to your pipeline, this isn't the node for it.

    Metadata disappears too. Pillow decoded the pixels and this pipeline writes no PNG text chunks, so a workflow embedded in the original PNG does not survive the round trip. The whole "the PNG is the project file" convention in this ecosystem dies at this hop.

    Size. A 2 MB PNG is roughly 2.7 million characters of text. Fine over an API, unpleasant in a node widget, and genuinely awful pasted into a workflow JSON. Wire the string in, don't hand-paste it.

    Finally, the trust question, since custom nodes run arbitrary Python on import with your user account and no sandbox: this pack is MIT, makes no network calls, pulls in nothing ComfyUI doesn't already have, and keeps the entire conversion in one readable file (src/utils/tensor.py). Two minutes of reading and you know everything it does to your data.

    CategorySimpleUtils/Image

    Inputs (1)

    NameTypeDefaultDescription
    base64STRINGThe base64 string to transform.

    Outputs (1)

    NameTypeDescription
    IMAGEIMAGE—