{"record":{"id":"2ea36d746a7675af","repo":"invoke-ai/InvokeAI","slug":"unable-to-load-pixels-from-subject-image","errorCode":null,"errorMessage":"Unable to load pixels from subject image","messagePattern":"Unable to load pixels from subject image","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"invokeai/app/invocations/composition-nodes.py","lineNumber":1336,"sourceCode":"        if image_background.height == 0 or image_background.width == 0:\n            raise ValueError(\"The subject image has zero height or width\")\n\n        # Handle backdrop removal:\n        chroma_key = self.chroma_key.strip()\n        if 0 < len(chroma_key):\n            # Remove pixels by chroma key:\n            if chroma_key[0] == \"(\":\n                chroma_key = tuple_from_string(chroma_key)\n                while len(chroma_key) < 3:\n                    chroma_key = tuple(list(chroma_key) + [0])\n                if len(chroma_key) == 3:\n                    chroma_key = tuple(list(chroma_key) + [255])\n            else:\n                chroma_key = ImageColor.getcolor(chroma_key, \"RGBA\")\n            threshold = self.threshold**2.0  # to compare vs squared color distance from key\n            pixels = image_subject.load()\n            if pixels is None:\n                raise ValueError(\"Unable to load pixels from subject image\")\n            for i in range(image_subject.width):\n                for j in range(image_subject.height):\n                    if (\n                        reduce(\n                            lambda a, b: a + b, [(pixels[i, j][k] - chroma_key[k]) ** 2 for k in range(len(chroma_key))]\n                        )\n                        < threshold\n                    ):\n                        pixels[i, j] = tuple([0 for k in range(len(chroma_key))])\n        else:\n            # Remove pixels by flood select from corners:\n            ImageDraw.floodfill(image_subject, (0, 0), (0, 0, 0, 0), thresh=self.threshold)\n            ImageDraw.floodfill(image_subject, (0, image_subject.height - 1), (0, 0, 0, 0), thresh=self.threshold)\n            ImageDraw.floodfill(image_subject, (image_subject.width - 1, 0), (0, 0, 0, 0), thresh=self.threshold)\n            ImageDraw.floodfill(\n                image_subject, (image_subject.width - 1, image_subject.height - 1), (0, 0, 0, 0), thresh=self.threshold\n            )\n","sourceCodeStart":1318,"sourceCodeEnd":1354,"githubUrl":"https://github.com/invoke-ai/InvokeAI/blob/0b6a024f2ff6a86bfb953dcdb9cc504ef7397a06/invokeai/app/invocations/composition-nodes.py#L1318-L1354","documentation":"After resolving the chroma key color, invoke() calls image_subject.load() to get the pixel-access buffer for the per-pixel distance loop. PIL returns None if pixel access cannot be established; the node raises instead of crashing with a TypeError inside the loop.","triggerScenarios":"invoke() with chroma key configured, where image_subject.load() returns None (PIL could not allocate/access the pixel buffer for the image).","commonSituations":"Degenerate or corrupt image data in the image store; exotic image modes that failed RGBA conversion; very large images exhausting memory during pixel-access initialization.","solutions":["Re-generate/re-upload the subject image and retry.","Convert the image explicitly before the node (e.g. img.convert('RGBA')) to ensure a loadable pixel buffer.","Update Pillow to a recent version; check available memory if the image is very large."],"exampleFix":"# before\npixels = image_subject.load()  # None for corrupt image\n# after\nimage_subject = image_subject.convert(\"RGBA\")\npixels = image_subject.load()\nif pixels is None:\n    raise ValueError(\"re-generate the subject image\")","handlingStrategy":"try-catch","validationCode":"pixels = image_subject.load()\nif pixels is None:\n    raise ValueError(\"subject image pixel buffer unavailable; regenerate image\")","typeGuard":null,"tryCatchPattern":"try:\n    output = node.invoke(context)\nexcept ValueError as e:\n    if \"Unable to load pixels\" in str(e):\n        image = reencode_image(context.images.get_pil(name).convert(\"RGBA\"))\n        retry_composition(image)\n    else:\n        raise","preventionTips":["Re-encode/re-save images through Pillow before heavy pixel processing","Keep Pillow updated to avoid pixel-access bugs","Monitor memory for very large images before per-pixel loops"],"tags":["images","pil","composition","pixel-access"],"backgroundTag":"image-load-failed","analyzedSha":"0b6a024f2ff6a86bfb953dcdb9cc504ef7397a06","analyzedAt":"2026-08-29T04:46:49.967Z","schemaVersion":2},"datasetVersion":"2026-08-29T07:17:48.351Z"}