Fooocus-API icon indicating copy to clipboard operation
Fooocus-API copied to clipboard

Fix JPEG support

Open yak1ex opened this issue 1 year ago • 0 comments

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.

  1. Use jpeg as format specifier in Fooocus-API itself.
    • I think this is the simplest solution but it would be a public API change anyway.
  2. 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
  3. 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.

yak1ex avatar May 24 '24 16:05 yak1ex