Skip to content

Commit

Permalink
Merge pull request AUTOMATIC1111#16194 from light-and-ray/fix_cannot_…
Browse files Browse the repository at this point in the history
…write_mode_P_as_jpeg

fix OSError: cannot write mode P as JPEG
  • Loading branch information
AUTOMATIC1111 authored Jul 20, 2024
2 parents 7c8a4cc + 3d2dbef commit 7b99e14
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 2 deletions.
2 changes: 1 addition & 1 deletion modules/api/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ def encode_pil_to_base64(image):
image.save(output_bytes, format="PNG", pnginfo=(metadata if use_metadata else None), quality=opts.jpeg_quality)

elif opts.samples_format.lower() in ("jpg", "jpeg", "webp"):
if image.mode == "RGBA":
if image.mode in ("RGBA", "P"):
image = image.convert("RGB")
parameters = image.info.get('parameters', None)
exif_bytes = piexif.dump({
Expand Down
2 changes: 1 addition & 1 deletion modules/shared_state.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ def do_set_current_image(self):
errors.record_exception()

def assign_current_image(self, image):
if shared.opts.live_previews_image_format == 'jpeg' and image.mode == 'RGBA':
if shared.opts.live_previews_image_format == 'jpeg' and image.mode in ('RGBA', 'P'):
image = image.convert('RGB')
self.current_image = image
self.id_live_preview += 1

0 comments on commit 7b99e14

Please sign in to comment.