KutsuyaYuki / ABG_extension

228 stars 23 forks source link

JPG generated in batch mode #3

Closed mykeehu closed 1 year ago

mykeehu commented 1 year ago

I would like to use the extension in batch mode, but unfortunately I can't because it wants to save JPG instead of PNG (PNG is set in the webUI Settings tab). The input images are JPG, but you must save them in PNG because of the alpha channel. So when I try to save the cropped image, I get this error in batch mode:

Will process 1150 images, creating 1 new images for each.
0it [00:00, ?it/s]
Error completing request
Arguments: ('task(i7tglb34i3h3cl0)', 5, '', '', [], None, None, None, None, None, None, None, 20, 0, 4, 0, 1, False, False, 1, 1, 7, 0, -1.0, -1.0, 0, 0, 0, False, 512, 512, 2, 0, 32, 0, 'L:\\1000 Photography Poses', 'L:\\1000 Photography Poses\\Cutted', 9, '', '', 0.9, 5, '0.0001', False, 'None', '', 0.1, False, 0, '<ul>\n<li><code>CFG Scale</code> should be 2 or lower.</li>\n</ul>\n', True, True, '', '', True, 50, True, 1, 0, False, 4, 1, '<p style="margin-bottom:0.75em">Recommended settings: Sampling Steps: 80-100, Sampler: Euler a, Denoising strength: 0.8</p>', 128, 8, ['left', 'right', 'up', 'down'], 1, 0.05, 128, 4, 0, ['left', 'right', 'up', 'down'], False, False, False, False, '', '<p style="margin-bottom:0.75em">Will upscale the image by the selected scale factor; use width and height sliders to set tile size</p>', 64, 0, 2, 1, '', 0, '', True, True, False, True, True, '', False, 1, 'Both ▦', 'Generate masks', False, '', False, None, True, '', False, False, False, False, 'Auto', 0.5, 1, 0, 0, 384, 384, False, False, True, True, True, False, True, 1, False, False, 2.5, 4, 0, False, 0, 1, False, False, 'u2net', False, False, False) {}
Traceback (most recent call last):
  File "H:\Stable-Diffusion-Automatic\stable-diffusion-webui\venv\lib\site-packages\PIL\JpegImagePlugin.py", line 643, in _save
    rawmode = RAWMODE[im.mode]
KeyError: 'RGBA'

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

Traceback (most recent call last):
  File "H:\Stable-Diffusion-Automatic\stable-diffusion-webui\modules\call_queue.py", line 56, in f
    res = list(func(*args, **kwargs))
  File "H:\Stable-Diffusion-Automatic\stable-diffusion-webui\modules\call_queue.py", line 37, in f
    res = func(*args, **kwargs)
  File "H:\Stable-Diffusion-Automatic\stable-diffusion-webui\modules\img2img.py", line 142, in img2img
    process_batch(p, img2img_batch_input_dir, img2img_batch_output_dir, args)
  File "H:\Stable-Diffusion-Automatic\stable-diffusion-webui\modules\img2img.py", line 59, in process_batch
    processed_image.save(os.path.join(output_dir, filename))
  File "H:\Stable-Diffusion-Automatic\stable-diffusion-webui\venv\lib\site-packages\PIL\Image.py", line 2431, in save
    save_handler(self, fp, filename)
  File "H:\Stable-Diffusion-Automatic\stable-diffusion-webui\venv\lib\site-packages\PIL\JpegImagePlugin.py", line 646, in _save
    raise OSError(msg) from e
OSError: cannot write mode RGBA as JPEG

Please fix it, because I need this plugin to crop a lot of images!

KutsuyaYuki commented 1 year ago

I've updated my repo, I think this should do the trick. Let me know if it doesn't!

KutsuyaYuki commented 1 year ago

Batch still seems to not work properly. This is an issue with WebUI. It does work in normal img2img with jpg now, but batch mode ignores the file extension I've set.

mykeehu commented 1 year ago

Then I'll take an issue for this at Automatic. Thanks for the fix!