Repository: stable-diffusion-webui
Issue: [Bug]: Textual Inversion image preprocessor crashes unexpectedly when using auto focal point crop
Labels: bug-report

### Is there an existing issue for this?

- [X] I have searched the existing issues and checked the recent builds/commits

### What happened?

The image processor for training embeds and hypernetworks crashes when processing images using auto focal crop.

### Steps to reproduce the problem

1. Go to the WebUI
2. Click on the Train tab
3. Navigate to "Preprocess images"
4. Input both directories, choose any image resolution
5. Check "auto focal point crop"
6. Wait for the processor to crash.
7. Uncheck "auto focal point crop"
8. Restart the processor and watch it complete all images.

### What should have happened?

The images should've been processed and cropped to target resolution.

### Commit where the problem happens

865af20

### What platforms do you use to access UI ?

Windows

### What browsers do you use to access the UI ?

Mozilla Firefox

### Command Line Arguments

```Shell
--xformers --opt-split-attention --opt-channelslast --no-half-vae --enable-insecure-extension-access --autolaunch --listen
```


### Additional information, context and logs

The crash log (processor crashes when processing image 3)

Preprocessing [Image 3/31]:  10%|█████▎                                                 | 3/31 [00:16<02:35,  5.56s/it]
Error completing request
Arguments: ('task(ntca3qagsimwm00)', 'G:\\NovelAI\\stable-diffusion-webui\\training_images\\input', 'G:\\NovelAI\\stable-diffusion-webui\\training_images\\output', 1280, 1280, 'ignore', False, False, False, False, 0.5, 0.2, True, 1, 0.15, 0.5, False, False, 384, 768, 4096, 409600, 'Maximize area', 0.1) {}
Traceback (most recent call last):
  File "G:\NovelAI\stable-diffusion-webui\modules\call_queue.py", line 56, in f
    res = list(func(*args, **kwargs))
  File "G:\NovelAI\stable-diffusion-webui\modules\call_queue.py", line 37, in f
    res = func(*args, **kwargs)
  File "G:\NovelAI\stable-diffusion-webui\modules\textual_inversion\ui.py", line 19, in preprocess
    modules.textual_inversion.preprocess.preprocess(*args)
  File "G:\NovelAI\stable-diffusion-webui\modules\textual_inversion\preprocess.py", line 23, in preprocess
    preprocess_work(process_src, process_dst, process_width, process_height, preprocess_txt_action, process_flip, process_split, process_caption, process_caption_deepbooru, split_threshold, overlap_ratio, process_focal_crop, process_focal_crop_face_weight, process_focal_crop_entropy_weight, process_focal_crop_edges_weight, process_focal_crop_debug, process_multicrop, process_multicrop_mindim, process_multicrop_maxdim, process_multicrop_minarea, process_multicrop_maxarea, process_multicrop_objective, process_multicrop_threshold)
  File "G:\NovelAI\stable-diffusion-webui\modules\textual_inversion\preprocess.py", line 216, in preprocess_work
    save_pic(focal, index, params, existing_caption=existing_caption)
  File "G:\NovelAI\stable-diffusion-webui\modules\textual_inversion\preprocess.py", line 83, in save_pic
    save_pic_with_caption(image, index, params, existing_caption=existing_caption)
  File "G:\NovelAI\stable-diffusion-webui\modules\textual_inversion\preprocess.py", line 64, in save_pic_with_caption
    image.save(os.path.join(params.dstdir, f"{basename}.png"))
  File "G:\NovelAI\stable-diffusion-webui\venv\lib\site-packages\PIL\Image.py", line 2431, in save
    save_handler(self, fp, filename)
  File "G:\NovelAI\stable-diffusion-webui\venv\lib\site-packages\PIL\PngImagePlugin.py", line 1331, in _save
    data = name + b"\0\0" + zlib.compress(icc)
TypeError: a bytes-like object is required, not 'str'