Fooocus-API
Fooocus-API copied to clipboard
Fix JPEG support
Currently, at least in my environment, Fooocus-API can't write JPEG format due to errors.
This is because Pillow expects a format specifier for JPEG format as JPEG not as JPG.
There are at least three possible solutions.
- Use
jpegas format specifier inFooocus-APIitself.- I think this is the simplest solution but it would be a public API change anyway.
- Use Image.registered_extensions() to get format specifier, as done in this PR.
- I think this is the most generic solution.
- Stable Diffusion webui employs this logic: https://github.com/AUTOMATIC1111/stable-diffusion-webui/blob/1c0a0c4c26f78c32095ebc7f8af82f5c04fca8c0/modules/images.py#L570
- This requires Pillow 9.4.0 due to a weired issue fixed in https://github.com/python-pillow/Pillow/pull/6811
- Use a literal dictionary like
image_format = {"png":"png", "jpg":"jpeg", "webp":"webp"}.get(extension)
This PR employs option 2. If this is not aligned with your preference, I will create another PR.