Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Jpeg 100% quality save #1789

Closed
RodTDai opened this issue Jan 7, 2024 · 8 comments · Fixed by #1863
Closed

Jpeg 100% quality save #1789

RodTDai opened this issue Jan 7, 2024 · 8 comments · Fixed by #1863
Labels
enhancement New feature or request
Milestone

Comments

@RodTDai
Copy link

RodTDai commented Jan 7, 2024

Hey guys!
Should be nice to have an option to save image in JPEG 100% quality instead of png.
Thanks.

@mashb1t
Copy link
Collaborator

mashb1t commented Jan 7, 2024

Saving could be achieved relatively easy by changing the two lines

extension='png')
and
date_string, local_temp_filename, only_name = generate_temp_filename(folder=modules.config.path_outputs, extension='png')
accordingly.
Temp images in the browser are png base64 encoded images directly from pytorch_to_numpy as far as i could see and there is no conversion happening.
If you need the jpg/jpeg results only in your outputs folder, feel free to change private_logger.py accordingly.

Enhancement: make this configurable.

@mashb1t mashb1t added the enhancement New feature or request label Jan 7, 2024
@RodTDai
Copy link
Author

RodTDai commented Jan 8, 2024

nice. Yes configurability is important here, because when system update files, we loose that custom modifications.
Thanks

@eddyizm
Copy link
Contributor

eddyizm commented Jan 10, 2024

A config something like this ?
image

I got the front end mostly working but need to figure out how to update the configuration using gradio if this works.

@eddyizm
Copy link
Contributor

eddyizm commented Jan 11, 2024

tested my pr locally but did not see any unit tests. If this needs to save to the file to maintain state, I can update my PR.

@mashb1t mashb1t linked a pull request Jan 11, 2024 that will close this issue
@drdancm
Copy link

drdancm commented Jan 11, 2024

This would be a wonderful enhancement.

@RodTDai
Copy link
Author

RodTDai commented Jan 11, 2024

actually a change for gradio is a good thing, as it can become super slow when running machine at home and accessing via mobile. Jpeg will help that too.

@Irmagon
Copy link

Irmagon commented Jan 15, 2024

The description of the method Image.save() says:

The image quality, on a scale from 1 (worst) to 95 (best). The default is 75. Values above 95 should be avoided; 100 disables portions of the JPEG compression algorithm, and results in large files with hardly any gain in image quality.

For 100% JPG qiality need add an additional parameter image_quality specifying the JPG compression ratio.
And setting this in UI input box or config.txt.
Because the default value of 75% will be applied for JPG file extension.

For example for 100% JPG: Image.fromarray(img).save(local_temp_filename, quality=95)

@mashb1t
Copy link
Collaborator

mashb1t commented Jan 16, 2024

@Irmagon already noticed when implementing #1940, fixed in f126102

@mashb1t mashb1t added this to the 2.2.0 milestone Feb 25, 2024
mashb1t pushed a commit that referenced this issue Feb 26, 2024
* feature: added flag, config and ui update for image extension change #1789

* moved function to config module

* moved image extension to webui via async worker. Passing as parameter to log and get_current_html_path functions per feedback

* check flag before displaying image extension radio button

* disabled if image log flag is passed in

* fix: add missing image_extension parameter to log call

* refactor: change label

* feat: add webp to image_extensions

supported image extemsions: see https://pillow.readthedocs.io/en/stable/handbook/image-file-formats.html

* feat: use consistent file name in gradio

returns and uses filepaths instead of numpy image by saving to temp dir
uses double the temp dir file storage on disk as it saves to temp dir and gradio temp dir when displaying the image, but reuses logged output image

* feat: delete temp images after yielding to gradio

* feat: use args temp path if given

* chore: code cleanup, remove redundant if statement

* feat: always show image_extension element

this is now possible due to image extension support in gradio via #1932

* refactor: rename image_extension to image_file_extension

* feat: use optimized jpg parameters when saving the image

quality=95
optimize=True
progressive=True

* refactor: rename image_file_extension to output_format

* feat: add exif handling

* refactor: code cleanup, remove items from metadata output

---------

Co-authored-by: Manuel Schmid <dev@mash1t.de>
Co-authored-by: Manuel Schmid <9307310+mashb1t@users.noreply.github.com>
Co-authored-by: Manuel Schmid <manuel.schmid@odt.net>
Co-authored by: eddyizm <wtfisup@hotmail.com>
mashb1t added a commit that referenced this issue Feb 26, 2024
…1863)

* feature: added flag, config and ui update for image extension change #1789

* moved function to config module

* moved image extension to webui via async worker. Passing as parameter to log and get_current_html_path functions per feedback

* check flag before displaying image extension radio button

* disabled if image log flag is passed in

* fix: add missing image_extension parameter to log call

* refactor: change label

* feat: add webp to image_extensions

supported image extemsions: see https://pillow.readthedocs.io/en/stable/handbook/image-file-formats.html

* feat: use consistent file name in gradio

returns and uses filepaths instead of numpy image by saving to temp dir
uses double the temp dir file storage on disk as it saves to temp dir and gradio temp dir when displaying the image, but reuses logged output image

* feat: delete temp images after yielding to gradio

* feat: use args temp path if given

* chore: code cleanup, remove redundant if statement

* feat: always show image_extension element

this is now possible due to image extension support in gradio via #1932

* refactor: rename image_extension to image_file_extension

* feat: use optimized jpg parameters when saving the image

quality=95
optimize=True
progressive=True

* refactor: rename image_file_extension to output_format

* feat: add exif handling

* refactor: code cleanup, remove items from metadata output

---------

Co-authored-by: Manuel Schmid <dev@mash1t.de>
Co-authored-by: Manuel Schmid <9307310+mashb1t@users.noreply.github.com>
Co-authored-by: Manuel Schmid <manuel.schmid@odt.net>
Co-authored by: eddyizm <wtfisup@hotmail.com>
@mashb1t mashb1t closed this as completed Feb 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants