Skip to content

fix: normalize JPG→JPEG format string before passing to Pillow#36

Open
TheSkyentist wants to merge 1 commit intoLeandroBarone:masterfrom
TheSkyentist:fix/jpg-format-pillow
Open

fix: normalize JPG→JPEG format string before passing to Pillow#36
TheSkyentist wants to merge 1 commit intoLeandroBarone:masterfrom
TheSkyentist:fix/jpg-format-pillow

Conversation

@TheSkyentist
Copy link
Copy Markdown

Summary

  • to_image_file() documents file_type='JPG' as a valid argument, but Pillow's Image.save() only recognises 'JPEG' — passing 'JPG' raises KeyError: 'JPG' at runtime.
  • Fix normalises the alias at the call site (_save_list_to_image_file, line 574) with a single conversion before the img.save() call.
  • Adds test_to_image_file_jpg to cover the previously-crashing code path.

Reproducer (before fix)

import ascii_magic
from PIL import Image

art = ascii_magic.AsciiArt(Image.open("photo.jpg").convert("RGB"))
art.to_image_file("out.jpg", file_type="JPG")
# KeyError: 'JPG'

Test plan

  • test_to_image_file_jpg passes (new test exercising file_type='JPG')
  • All existing test_to_image_file_* tests continue to pass (9/9)

🤖 Generated with Claude Code

Pillow's Image.save() raises KeyError when given 'JPG' because it only
recognises 'JPEG' as the JPEG format identifier. The public to_image_file()
API advertises 'JPG' as a valid file_type, so normalise the alias at the
call site rather than silently breaking.

Add test_to_image_file_jpg to cover the previously-crashing code path.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant