lllyasviel/Fooocus · error · Error

Unsupported image type in input

Error message

Unsupported image type in input

What it means

preprocess() of the vendored gradio Image first asserts the input is a base64 string, then decodes it with processing_utils.decode_base64_to_image. If PIL raises PIL.UnidentifiedImageError (data decoded but is not a recognizable image format), it is re-raised as the gradio Error('Unsupported image type in input'). Corrupt payloads that fail decoding entirely propagate the original decoding exception instead.

Source

Thrown at modules/gradio_hijack.py:281

        Parameters:
            x: base64 url data, or (if tool == "sketch") a dict of image and mask base64 url data
        Returns:
            image in requested format, or (if tool == "sketch") a dict of image and mask in requested format
        """
        if x is None:
            return x

        mask = None

        if self.tool == "sketch" and self.source in ["upload", "webcam"]:
            if isinstance(x, dict):
                x, mask = x["image"], x["mask"]

        assert isinstance(x, str)
        try:
            im = processing_utils.decode_base64_to_image(x)
        except PIL.UnidentifiedImageError:
            raise Error("Unsupported image type in input")
        with warnings.catch_warnings():
            warnings.simplefilter("ignore")
            im = im.convert(self.image_mode)
        if self.shape is not None:
            im = processing_utils.resize_and_crop(im, self.shape)
        if self.invert_colors:
            im = PIL.ImageOps.invert(im)
        if (
            self.source == "webcam"
            and self.mirror_webcam is True
            and self.tool != "color-sketch"
        ):
            im = PIL.ImageOps.mirror(im)

        if self.tool == "sketch" and self.source in ["upload", "webcam"]:
            if mask is not None:
                mask_im = processing_utils.decode_base64_to_image(mask)
                if mask_im.mode == "RGBA":  # whiten any opaque pixels in the mask

View on GitHub (pinned to ae05379cc9)

Solutions

  1. Validate/convert the payload before sending: open with PIL.Image.open and re-save as PNG, then base64-encode.
  2. Strip any 'data:image/...;base64,' prefix if your path produces it and the component does not expect it.
  3. Ensure Pillow is recent enough for the source format (HEIF/AVIF need extra plugins) or convert client-side to JPEG/PNG.

Example fix

# before
import base64; b64 = base64.b64encode(open('doc.pdf','rb').read()).decode()
# after
from PIL import Image; import io, base64
buf = io.BytesIO(); Image.open('in.heic').convert('RGB').save(buf, 'PNG')
b64 = base64.b64encode(buf.getvalue()).decode()
Defensive patterns

Strategy: validation

Validate before calling

import base64, io
from PIL import Image
def to_safe_b64(data: bytes) -> str:
    im = Image.open(io.BytesIO(data)); im.load()  # raises now, not in the UI
    buf = io.BytesIO(); im.convert('RGB').save(buf, 'PNG')
    return base64.b64encode(buf.getvalue()).decode()

Type guard

def is_decodable_image_b64(b64: str) -> bool:
    try:
        Image.open(io.BytesIO(base64.b64decode(b64))).verify(); return True
    except Exception:
        return False

Try / catch

try:
    im = processing_utils.decode_base64_to_image(x)
except PIL.UnidentifiedImageError:
    raise gr.Error('Unsupported image type in input — send PNG/JPEG base64')

Prevention

When it happens

Trigger: A frontend/API client sends base64 of a PDF, TIFF variant PIL cannot read, truncated file, or a data URI where the actual bytes are not an image; tool=='sketch' payloads whose 'image' field carries non-image bytes.

Common situations: Calling Fooocus's gradio endpoints with raw file bytes base64-encoded without validation; proxying images through a service that mangles content-type; browsers sending HEIC/AVIF on unsupported Pillow builds.

Related errors


AI-assisted analysis of lllyasviel/Fooocus@ae05379cc9 (2026-08-15). Data as JSON: /api/errors/34318d8d48a43491. Report an issue: GitHub.