{"record":{"id":"34318d8d48a43491","repo":"lllyasviel/Fooocus","slug":"unsupported-image-type-in-input","errorCode":null,"errorMessage":"Unsupported image type in input","messagePattern":"Unsupported image type in input","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"modules/gradio_hijack.py","lineNumber":281,"sourceCode":"        Parameters:\n            x: base64 url data, or (if tool == \"sketch\") a dict of image and mask base64 url data\n        Returns:\n            image in requested format, or (if tool == \"sketch\") a dict of image and mask in requested format\n        \"\"\"\n        if x is None:\n            return x\n\n        mask = None\n\n        if self.tool == \"sketch\" and self.source in [\"upload\", \"webcam\"]:\n            if isinstance(x, dict):\n                x, mask = x[\"image\"], x[\"mask\"]\n\n        assert isinstance(x, str)\n        try:\n            im = processing_utils.decode_base64_to_image(x)\n        except PIL.UnidentifiedImageError:\n            raise Error(\"Unsupported image type in input\")\n        with warnings.catch_warnings():\n            warnings.simplefilter(\"ignore\")\n            im = im.convert(self.image_mode)\n        if self.shape is not None:\n            im = processing_utils.resize_and_crop(im, self.shape)\n        if self.invert_colors:\n            im = PIL.ImageOps.invert(im)\n        if (\n            self.source == \"webcam\"\n            and self.mirror_webcam is True\n            and self.tool != \"color-sketch\"\n        ):\n            im = PIL.ImageOps.mirror(im)\n\n        if self.tool == \"sketch\" and self.source in [\"upload\", \"webcam\"]:\n            if mask is not None:\n                mask_im = processing_utils.decode_base64_to_image(mask)\n                if mask_im.mode == \"RGBA\":  # whiten any opaque pixels in the mask","sourceCodeStart":263,"sourceCodeEnd":299,"githubUrl":"https://github.com/lllyasviel/Fooocus/blob/ae05379cc97bc4361ec8b4ec90193dab21be763f/modules/gradio_hijack.py#L263-L299","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Validate/convert the payload before sending: open with PIL.Image.open and re-save as PNG, then base64-encode.","Strip any 'data:image/...;base64,' prefix if your path produces it and the component does not expect it.","Ensure Pillow is recent enough for the source format (HEIF/AVIF need extra plugins) or convert client-side to JPEG/PNG."],"exampleFix":"# before\nimport base64; b64 = base64.b64encode(open('doc.pdf','rb').read()).decode()\n# after\nfrom PIL import Image; import io, base64\nbuf = io.BytesIO(); Image.open('in.heic').convert('RGB').save(buf, 'PNG')\nb64 = base64.b64encode(buf.getvalue()).decode()","handlingStrategy":"validation","validationCode":"import base64, io\nfrom PIL import Image\ndef to_safe_b64(data: bytes) -> str:\n    im = Image.open(io.BytesIO(data)); im.load()  # raises now, not in the UI\n    buf = io.BytesIO(); im.convert('RGB').save(buf, 'PNG')\n    return base64.b64encode(buf.getvalue()).decode()","typeGuard":"def is_decodable_image_b64(b64: str) -> bool:\n    try:\n        Image.open(io.BytesIO(base64.b64decode(b64))).verify(); return True\n    except Exception:\n        return False","tryCatchPattern":"try:\n    im = processing_utils.decode_base64_to_image(x)\nexcept PIL.UnidentifiedImageError:\n    raise gr.Error('Unsupported image type in input — send PNG/JPEG base64')","preventionTips":["Client-side, always re-encode to PNG/JPEG via PIL before base64-embedding.","Verify payloads with Image.open(...).verify() before submitting to the endpoint."],"tags":["gradio","base64","image-decoding","pillow","input-validation"],"backgroundTag":null,"analyzedSha":"ae05379cc97bc4361ec8b4ec90193dab21be763f","analyzedAt":"2026-08-15T04:23:59.533Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}