stable-diffusion-webui-scripts icon indicating copy to clipboard operation
stable-diffusion-webui-scripts copied to clipboard

[BUG]: Does not work with .jpg

Open Zyin055 opened this issue 3 years ago • 1 comments

Description of the bug

When using "File format for images" set to "jpg" in the Automatic1111 settings tab, produces the following error when using the script with default settings:

  File "C:\Stuff\AI\Stable Diffusion\venv\lib\site-packages\PIL\JpegImagePlugin.py", line 630, in _save
    rawmode = RAWMODE[im.mode]
KeyError: 'P'

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "C:\Stuff\AI\Stable Diffusion\modules\ui.py", line 185, in f
    res = list(func(*args, **kwargs))
  File "C:\Stuff\AI\Stable Diffusion\webui.py", line 54, in f
    res = func(*args, **kwargs)
  File "C:\Stuff\AI\Stable Diffusion\modules\txt2img.py", line 45, in txt2img
    processed = modules.scripts.scripts_txt2img.run(p, *args)
  File "C:\Stuff\AI\Stable Diffusion\modules\scripts.py", line 296, in run
    processed = script.run(p, *script_args)
  File "C:\Stuff\AI\Stable Diffusion\scripts\pixel_art.py", line 72, in run
    images.save_image(proc.images[i], p.outpath_samples, "",
  File "C:\Stuff\AI\Stable Diffusion\modules\images.py", line 520, in save_image
    image.save(fullfn, quality=opts.jpeg_quality)
  File "C:\Stuff\AI\Stable Diffusion\venv\lib\site-packages\PIL\Image.py", line 2320, in save
    save_handler(self, fp, filename)
  File "C:\Stuff\AI\Stable Diffusion\venv\lib\site-packages\PIL\JpegImagePlugin.py", line 632, in _save
    raise OSError(f"cannot write mode {im.mode} as JPEG") from e
OSError: cannot write mode P as JPEG

Setting it to "png" makes it work as expected.

Steps To Reproduce

  1. "File format for images" set to "jpg"
  2. Use the script to generate any image

Additional Information

No response

Zyin055 avatar Nov 29 '22 18:11 Zyin055

Any resolution for this issue? Switching to PNG for the time being helps, but really would like to keep the jpg format

phrozen avatar Apr 28 '23 20:04 phrozen