Repository: stable-diffusion-webui
Issue: [Bug]: File format for images accepts invalid inputs, breaks API response
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?

It's possible to enter invalid image file formats in the settings, resulting in invalid responses from the API. Even valid formats, but entered with an additional dot like '.png' instead of 'png' breaks the API response. This does not affect the web-ui, only the API response.

```
{
  "error": "HTTPException",
  "detail": "Invalid image format",
  "body": "",
  "errors": ""
}
```

### Steps to reproduce the problem

1. Go to Settings
2. Press Saving images/grid
3. Change file format to someting like '.png', '.jpg' or 'abc'
4. Make a valid API request
5. Result:

```
{
  "error": "HTTPException",
  "detail": "Invalid image format",
  "body": "",
  "errors": ""
}
```

### What should have happened?

The 'File format for images' field as well as the 'File format for grids' field should make an input-validation to prevent wrong image formats like 'aaa' or additional dots etc. on valid formats like '.png' or '.jpg'.

Maybe a drop-down with predefined formats is the best way to prevent invalid inputs.

### Sysinfo

[sysinfo-2023-09-01-10-47.txt](https://github.com/AUTOMATIC1111/stable-diffusion-webui/files/12497123/sysinfo-2023-09-01-10-47.txt)


### What browsers do you use to access the UI ?

Google Chrome

### Console logs

```Shell
ubuntu@stable-diffusion:~$ ~/stable-diffusion-webui/webui.sh --listen --port 4000 --xformers --api --gradio-auth fuels:sleuf --api-auth fuels:sleuf --cors-allow-origins=* --no-download-sd-model --no-gradio-queue --no-half-vae

################################################################
Install script for stable-diffusion + Web UI
Tested on Debian 11 (Bullseye)
################################################################

################################################################
Running on ubuntu user
################################################################

################################################################
Create and activate python venv
################################################################

################################################################
Launching launch.py...
################################################################
Cannot locate TCMalloc (improves CPU memory usage)
Python 3.10.12 (main, Jun 11 2023, 05:26:28) [GCC 11.4.0]
Version: v1.6.0
Commit hash: 5ef669de080814067961f28357256e8fe27544f4
Launching Web UI with arguments: --listen --port 4000 --xformers --api --gradio-auth USER:PASS --api-auth USER:PASS --cors-allow-origins=* --no-download-sd-model --no-gradio-queue --no-half-vae
Loading weights [31e35c80fc] from /home/ubuntu/stable-diffusion-webui/stable-diffusion-webui/models/Stable-diffusion/sd_xl_base_1.0.safetensors
Creating model from config: /home/ubuntu/stable-diffusion-webui/stable-diffusion-webui/repositories/generative-models/configs/inference/sd_xl_base.yaml
Running on local URL:  http://0.0.0.0:4000

To create a public link, set `share=True` in `launch()`.
Startup time: 8.2s (prepare environment: 1.4s, import torch: 2.1s, import gradio: 0.6s, setup paths: 1.0s, initialize shared: 0.2s, other imports: 0.4s, load scripts: 0.6s, initialize extra networks: 0.9s, create ui: 0.4s, gradio launch: 0.6s).
Applying attention optimization: xformers... done.
Model loaded in 3.8s (load weights from disk: 0.8s, create model: 1.4s, apply weights to model: 1.3s, calculate empty prompt: 0.1s).
 80%|█████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████▌                                            | 20/25 [00:02<00:00,  7.43it/s]Reusing loaded model sd_xl_base_1.0.safetensors [31e35c80fc] to load sd_xl_refiner_1.0.safetensors [7440042bbd]██████████████████████████████████████████████████████████████████████████▊                                         | 20/25 [00:02<00:00,  7.46it/s]
Loading weights [7440042bbd] from /home/ubuntu/stable-diffusion-webui/stable-diffusion-webui/models/Stable-diffusion/sd_xl_refiner_1.0.safetensors
Creating model from config: /home/ubuntu/stable-diffusion-webui/stable-diffusion-webui/repositories/generative-models/configs/inference/sd_xl_refiner.yaml
Applying attention optimization: xformers... done.
Model loaded in 1.3s (create model: 0.1s, apply weights to model: 1.0s).
100%|██████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 25/25 [00:09<00:00,  2.60it/s]
Total progress: 100%|██████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 25/25 [00:09<00:00,  2.63it/s]
Total progress: 100%|██████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 25/25 [00:09<00:00,  1.75it/s]
```


### Additional information

_No response_