Repository: stable-diffusion-webui
Issue: [Bug]: img2img Batch - PNG Info and Save text file Missing / Not working with custom Output dir- Updated
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?

Version Run on Windows 10.
commit 0cc0ee1bcb4c24a8c9715f66cede06601bfc00c8 (HEAD -> master, origin/master, origin/HEAD)
Merge: 65995a2e f71a3c9c
Author: AUTOMATIC1111 <16777216c@gmail.com>
Date:   Mon Feb 20 14:45:54 2023 +0300

Problem Description:
When using Img2Img Batch tab, the final image output does not come with png info for generation.
Additionally, Save text information is not produced.

### Steps to reproduce the problem

1. Go to Img2Img - Batch Tab
2. Specify Input and Output folders (Output folder blank does not cause bug)
3. Specify prompt and settings for generation (anything)
4. Generate
5. Inspect the resultant file in PNG Info
6. Despair at provided info.
![image](https://user-images.githubusercontent.com/10180433/220834712-dfe69f30-f370-4b22-a42c-21255054c66f.png)
7. Hope that there is a .txt file with parameters saved.
8. Despair as no such files were generated.

### What should have happened?

The normal process not including Batch provides full PNG information embedded into a final file. Additionally if selected from the options the .txt file with the same information is produced to accompany the generated image.

None of these options happen, which is devastating after running Batch Img2Img for over 24 hours and realizing that all the seed and prompt information I wanted to gather is simply not there.

UPDATE:
It turns out this bug is a bit more complex than what I wrote out initially. It DOES NOT happen if you leave the output directory empty which defaults to the 'general output' directory and whatever format for directory output you have in settings. If you leave the directory output empty during a batch, it correctly saves the following: image before color correction, image after color correction, txt files for both. In this case, both png info files are in fact saved correctly within the file.

What happens when you run it with the output directory specified, is that you get a single image file. No distinction before color correction and after, and also no .txt files for them. You also lose png information from the file.

### Commit where the problem happens

0cc0ee1bcb4c24a8c9715f66cede06601bfc00c8 

### What platforms do you use to access the UI ?

Windows

### What browsers do you use to access the UI ?

Google Chrome

### Command Line Arguments

```Shell
set COMMANDLINE_ARGS=--api
```


### List of extensions

custom_sd_save_intermediate_images	https://github.com/AlUlkesh/sd_save_intermediate_images.git	929fa07a (Sat Feb 11 22:40:52 2023)	unknown
stable-diffusion-webui-instruct-pix2pix	https://github.com/Klace/stable-diffusion-webui-instruct-pix2pix.git	a5a4c6b8 (Sun Feb 5 22:19:05 2023)	unknown


### Console logs

```Shell
No logs. The application thinks it did a splendid job and continues on with no errors.
```


### Additional information

I ended up using sd_save_intermediate_images extension to 'mitigate the issue'. This extension correctly saves the png information in file as well as provides text file associated. I did modify the sd_save_intermediate_images  as I did not like that the extension kept overwriting my files (when input file in batch is run again and filename is used again).

The issue described however happened before installing any of the extensions listed.



Additional 'Weird' Behaviour for Img2Img Batch tab, which I am unsure how to address but might be related is that the final image is not saved immediately to output folders. This causes the generated images to be 'missing' for a long while or even never get saved when program crashes or is terminated. I need to investigate this further but intermediate images with sd_save_intermediate_images  are saved pretty much instantly from the point of reaching step specified in the terminal window progress bar, while the corresponding 'final' file is not even created after a bunch of other files were created. I suspected that this was linked to the number of lines or batch count for specified input file as I noticed that batch of 5 seemed to be saving 5 files at once, but this was not thoroughly tested.