Do not convert to JPEG if not possible
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
May I ask, what is this "Export for 4chan" thing?
@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 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!
https://github.com/AUTOMATIC1111/stable-diffusion-webui/blob/c429bcc5d8ec1710ef3f262a0acd6ec3bea9d474/modules/images.py#L553-L555 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")
@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.
JPEG doesn't support 16 bit, thus the error,
related PR https://github.com/AUTOMATIC1111/stable-diffusion-webui/pull/7564 will have merge conflict if one gets merge first
another related PR https://github.com/AUTOMATIC1111/stable-diffusion-webui/pull/7650
@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: https://github.com/python-pillow/Pillow/pull/3838#discussion_r292114051
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
should be fixed by fb2354cb2ae47f9e9b70f0e04f34925bbb31b1ac