mrhan1993 / Fooocus-API

FastAPI powered API for Fooocus
GNU General Public License v3.0
502 stars 131 forks source link

Fix JPEG support #339

Closed yak1ex closed 1 month ago

yak1ex commented 1 month ago

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.
  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.