thundaga / SD-webui-txt2img-script

Stable diffusion webui script to batch process images within the txt2img section
39 stars 5 forks source link

Saving image as .png instead of the default .jpg #28

Open wipdesigns opened 4 days ago

wipdesigns commented 4 days ago

When I used the script it worked fantastically, however, I neglected to check the extension of the file format as I'm used to having the files saved as a .jpg. In this instance, it processed 200-ish images in .png and to make it worse the script deleted the meta/exif so the .png file that it created is now no longer good to use as a reference via .png import in future for creating similar images.

In the settings I have the following: Saving images/grids>File format for images = .jpg

Process:

  1. Create images in txt2img (as .jpg)
  2. Save all images that I want to upscale via the scrip to a new folder
  3. Specify that folder in the scrip input location
  4. Clear all fields in txt2img
  5. Run the script (import image, use meta/exif, upscale via txt2img @2x, export to a new folder)

Note: the original file is generated in a .jpg

Is there a way to default the exporting of images to .jpg in your script rather than .png?

00000-4072635912-score_9, score_8, score_7, score_6, (semi-realistic_1 1), beautiful summer sunset over cliffs by the sea, English coastline, (la

OPCOXE commented 4 days ago

Hi, I'll check for the jpg output, I thought it uses the format in settings but maybe not. For the fact that it removes the exif data, you may want to try refreshing your tab before using the script because it shouldn't do that and it never happend for me (it may be cause by jpg format but that would be strange)

wipdesigns commented 4 days ago

Some extra info that might help!

I've just run another test:

Same as before (but this time with a portrait), this time with Adetailer running and 'Save images before ADetailer', the normal image through the script comes out as .jpg. The Adetailer version that saves afterwards comes out in .png! (even though if I txt2img with Adetailer without the strip the images save as a .jpg as set in the settings)

Is this something you're able to specify that Adetailer saves .jpg when used with your script?

wipdesigns commented 4 days ago

To further add to this.

The txt2img folder has the image saved as .jpg without Adetailer modifications, and the 'exported' folder has an image with Adetailer in .jpg and also one in .png

OPCOXE commented 4 days ago

I'm not sure I understood everything but the script isn't compatible with Adetailer in input. It may work in process tho. I did some test, I downloaded the image you posted put it in pnginfo to generate a similar image in png then run the script for both and no meta data was remove on either of the 4 images. So I assume there is something else of that. I'll now check for the jpg format but there is no real needs of implemting it since we can convert png to jpg

EDIT : Ok so after checking a few thing I found the that the default extension is png for save_image So the idea would be to check if we can get the setting "File format for images" and override the extension with it As a short fix, you may change the line 247 of the script for the following, it'll save images as jpg (you won't be able to do png with the script anymore) : images.save_image(image=processed_image, path=output_dir, extension='jpg', basename=basename, forced_filename=forced_filename, existing_info=processed_image.info)

wipdesigns commented 4 days ago

"no meta data was remove on either of the 4 images. So I assume there is something else of that."

Possibly, I'll have to do more testing on my side.

-

"I'll now check for the jpg format but there is no real needs of implement it since we can convert png to jpg"

I thought that, but if I convert .png to .jpg I lose the meta/exif no matter if I use Photoshop or an online image converter, hence why it's important for future image generation to keep the exif/meta within a smaller file size .jpg.

OPCOXE commented 4 days ago

You're right for the loss of metadata after converting. Here is the proper fix (same line) : images.save_image(image=processed_image, path=output_dir, extension=shared.opts.samples_format, basename=basename, forced_filename=forced_filename, existing_info=processed_image.info) @thundaga, can you add it directly to the repo or do you want me to create a pull request ? EDIT : I made a pull request (#29) to add the fix to the repo