Merge pull request #6644 from radarhere/convert

This commit is contained in:
Hugo van Kemenade 2022-10-19 10:22:00 +02:00 committed by GitHub
commit 87a9d7197e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 1 deletions

View File

@ -38,6 +38,12 @@ def test_sanity():
convert(im, output_mode)
def test_unsupported_conversion():
im = hopper()
with pytest.raises(ValueError):
im.convert("INVALID")
def test_default():
im = hopper("P")

View File

@ -1051,7 +1051,10 @@ class Image:
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