[Bug]: "PIL.UnidentifiedImageError: cannot identify image file" when inpainting with a PNG exported by GIMP
Is there an existing issue for this?
- [X] I have searched the existing issues and checked the recent builds/commits
What happened?
I was using img2img inpainting with an externally drawn mask, but when I click generate, it switches to the progress bar but doesn't add text to it or make progress, and I noticed this exception in the console:
Traceback (most recent call last):
File "E:\code\stable-diffusion-webui\venv\lib\site-packages\gradio\routes.py", line 284, in run_predict
output = await app.blocks.process_api(
File "E:\code\stable-diffusion-webui\venv\lib\site-packages\gradio\blocks.py", line 980, in process_api
inputs = self.preprocess_data(fn_index, inputs, state)
File "E:\code\stable-diffusion-webui\venv\lib\site-packages\gradio\blocks.py", line 891, in preprocess_data
processed_input.append(block.preprocess(inputs[i]))
File "E:\code\stable-diffusion-webui\venv\lib\site-packages\gradio\components.py", line 1358, in preprocess
im = processing_utils.decode_base64_to_image(x)
File "E:\code\stable-diffusion-webui\venv\lib\site-packages\gradio\processing_utils.py", line 47, in decode_base64_to_image
return Image.open(BytesIO(base64.b64decode(image_encoded)))
File "E:\code\stable-diffusion-webui\venv\lib\site-packages\PIL\Image.py", line 3147, in open
raise UnidentifiedImageError(
PIL.UnidentifiedImageError: cannot identify image file <_io.BytesIO object at 0x000001C9C8024FE0>
and then I seem to have to refresh the page to get the generate button back.
Steps to reproduce the problem
- Go to img2img inpainting
- Provide the image/mask below (I get this behavior with just the edited image and a browser-painted mask, or an uploaded mask.)
- Click generate

What should have happened?
Generating an image
Commit where the problem happens
7ba3923d5b494b7756d0b12f33acb3716d830b9a
What platforms do you use to access UI ?
Windows
What browsers do you use to access the UI ?
Mozilla Firefox
Command Line Arguments
No response
Additional information, context and logs
No response
When I (slightly changed the contrast so it would let me and) resaved the image with Windows' Photos editor, it stopped happening:

So that may make it relevant that I edited the photo with GIMP 2.10.8.
With a GIMP-saved JPG, there seems to be a different problem where inpainting hardly happens - it'll mostly stay white within the inpainting area and seemingly ignore the prompt, and it again doesn't happen when resaved by Photos, but I'll refrain from derailing further.
I was able to work around this problem by starting with the PNG that GIMP saved, flipping it and saving a copy with Photos, then flipping it back and overwriting the copy.
might be relevant: https://gitlab.gnome.org/GNOME/gimp/-/issues/2111
You're correct! It turns out both that my version of GIMP is old, and that this doesn't happen with 2.10.32. Thank you!
This issue also happens with JPEGs directly extracted from phones (eg, Huawei P40 Pro) and from other open-source softwares (Caesium Image Compressor). Exporting the image from the latest version of GIMP as a PNG worked to fix this issue.
So it seems that PIL (or is it PILLOW that is used here?) has some issues with some images, for some reason that is not clear, because I had no issue with these images with all the other graphical or non-graphical (eg, messengers) softwares I am using on a daily basis.