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

Do not convert to JPEG if not possible #7616

Closed
wants to merge 1 commit into from
Closed

Do not convert to JPEG if not possible #7616

wants to merge 1 commit into from

Conversation

semjon00
Copy link
Contributor

@semjon00 semjon00 commented Feb 7, 2023

Do not export for 4chan if conversion to JPEG is not possible. This prevents an exception when trying to save large depthmaps when export_for_4chan setting is on. See #6065

Do not export for 4chan if conversion to JPEG is not possible.
This prevents an exception when trying to save large depthmaps when export_for_4chan setting is on
@Nacurutu
Copy link

Nacurutu commented Feb 7, 2023

May I ask, what is this "Export for 4chan" thing?

@semjon00
Copy link
Contributor Author

semjon00 commented Feb 7, 2023

@Nacurutu It is an UI setting. If enabled, export every large/heavy image as a shrunk/smaller JPG. The setting has a "4MB" in its wording in the UI (sorry, I am not near a computer rn).

@Nacurutu
Copy link

Nacurutu commented Feb 7, 2023

@Nacurutu It is an UI setting. If enabled, export every large/heavy image as a shrunk/smaller JPG. The setting has a "4MB" in its wording in the UI (sorry, I am not near a computer rn).

thank you!

@missionfloyd
Copy link
Collaborator

missionfloyd commented Feb 8, 2023

elif extension.lower() in (".jpg", ".jpeg", ".webp"):
if image_to_save.mode == 'RGBA':
image_to_save = image_to_save.convert("RGB")

You could convert 16-bit to 8-bit before saving, like so:

elif extension.lower() in (".jpg", ".jpeg", ".webp"):
    if image_to_save.mode == 'RGBA':
        image_to_save = image_to_save.convert("RGB")
    elif image_to_save.mode == 'I;16':
        image_to_save = image_to_save.point(lambda p: p * 0.0038910505836576).convert("L")

@semjon00
Copy link
Contributor Author

semjon00 commented Feb 8, 2023

@missionfloyd Thanks for the .point(...) tip, good I now know that. I think to not use it here - I hardly can imagine anyone exporting 16 grayscale image and then complain why there was no version optimized for 4chan.

On another side, it could be very confusing if somebody writes code that should save 16 bit grayscale image as JPEG, but the quality of the saved images is worse than expected.

@missionfloyd
Copy link
Collaborator

JPEG doesn't support 16 bit, thus the error,

@w-e-w
Copy link
Collaborator

w-e-w commented Feb 8, 2023

related PR #7564
will have merge conflict if one gets merge first

@w-e-w
Copy link
Collaborator

w-e-w commented Feb 8, 2023

another related PR #7650

@semjon00
Copy link
Contributor Author

semjon00 commented Feb 9, 2023

@w-e-w ACK #7650. Will keep an eye on #7564 and rebase when it lands. Or maybe you could just take my patch and append it to your MR.

Another reason why not to try to convert 16bit monochrome JPEGs:
python-pillow/Pillow#3838 (comment)

@w-e-w
Copy link
Collaborator

w-e-w commented Feb 10, 2023

Or maybe you could just take my patch and append it to your MR.

yes I could, but I prefer to keep the issue separate

I think it's easier for AUTO to understand what's going on
and if he does wish to merge your it is a trivial conflict resolve

there is also a chance that AUTO decides to take a different approach
in that case it would definitely be better to keep them as separate PRs

@AUTOMATIC1111
Copy link
Owner

should be fixed by fb2354c

@semjon00 semjon00 deleted the semjon00-patch-1 branch June 28, 2023 19:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants