Skip to content

Commit

Permalink
Merge pull request #6644 from radarhere/convert
Browse files Browse the repository at this point in the history
  • Loading branch information
hugovk committed Oct 19, 2022
2 parents 340f247 + b8cd3e7 commit 87a9d71
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
6 changes: 6 additions & 0 deletions Tests/test_image_convert.py
Expand Up @@ -38,6 +38,12 @@ def convert(im, mode):
convert(im, output_mode)


def test_unsupported_conversion():
im = hopper()
with pytest.raises(ValueError):
im.convert("INVALID")


def test_default():

im = hopper("P")
Expand Down
5 changes: 4 additions & 1 deletion src/PIL/Image.py
Expand Up @@ -1051,7 +1051,10 @@ def convert_transparency(m, v):
except ValueError:
try:
# normalize source image and try again
im = self.im.convert(getmodebase(self.mode))
modebase = getmodebase(self.mode)
if modebase == self.mode:
raise
im = self.im.convert(modebase)
im = im.convert(mode, dither)
except KeyError as e:
raise ValueError("illegal conversion") from e
Expand Down

0 comments on commit 87a9d71

Please sign in to comment.