Merge pull request #5315 from radarhere/simplified

Simplified code
This commit is contained in:
Andrew Murray 2021-06-30 19:24:19 +10:00 committed by GitHub
commit cab9179a85
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1975,7 +1975,7 @@ class Image:
resample = NEAREST
if self.mode in ["LA", "RGBA"] and resample != NEAREST:
im = self.convert(self.mode[:-1] + "a")
im = self.convert({"LA": "La", "RGBA": "RGBa"}[self.mode])
im = im.resize(size, resample, box)
return im.convert(self.mode)
@ -2025,7 +2025,7 @@ class Image:
return self.copy()
if self.mode in ["LA", "RGBA"]:
im = self.convert(self.mode[:-1] + "a")
im = self.convert({"LA": "La", "RGBA": "RGBa"}[self.mode])
im = im.reduce(factor, box)
return im.convert(self.mode)
@ -2463,18 +2463,11 @@ class Image:
:returns: An :py:class:`~PIL.Image.Image` object.
"""
if self.mode == "LA" and resample != NEAREST:
if self.mode in ("LA", "RGBA") and resample != NEAREST:
return (
self.convert("La")
self.convert({"LA": "La", "RGBA": "RGBa"}[self.mode])
.transform(size, method, data, resample, fill, fillcolor)
.convert("LA")
)
if self.mode == "RGBA" and resample != NEAREST:
return (
self.convert("RGBa")
.transform(size, method, data, resample, fill, fillcolor)
.convert("RGBA")
.convert(self.mode)
)
if isinstance(method, ImageTransformHandler):