mirror of
https://github.com/python-pillow/Pillow.git
synced 2025-02-04 21:50:54 +03:00
Merge pull request #5594 from radarhere/convert
If default conversion from P is RGB with transparency, convert to RGBA
This commit is contained in:
commit
3307bf691f
|
@ -42,10 +42,14 @@ def test_default():
|
||||||
|
|
||||||
im = hopper("P")
|
im = hopper("P")
|
||||||
assert_image(im, "P", im.size)
|
assert_image(im, "P", im.size)
|
||||||
im = im.convert()
|
converted_im = im.convert()
|
||||||
assert_image(im, "RGB", im.size)
|
assert_image(converted_im, "RGB", im.size)
|
||||||
im = im.convert()
|
converted_im = im.convert()
|
||||||
assert_image(im, "RGB", im.size)
|
assert_image(converted_im, "RGB", im.size)
|
||||||
|
|
||||||
|
im.info["transparency"] = 0
|
||||||
|
converted_im = im.convert()
|
||||||
|
assert_image(converted_im, "RGBA", im.size)
|
||||||
|
|
||||||
|
|
||||||
# ref https://github.com/python-pillow/Pillow/issues/274
|
# ref https://github.com/python-pillow/Pillow/issues/274
|
||||||
|
|
|
@ -914,16 +914,18 @@ class Image:
|
||||||
|
|
||||||
self.load()
|
self.load()
|
||||||
|
|
||||||
|
has_transparency = self.info.get("transparency") is not None
|
||||||
if not mode and self.mode == "P":
|
if not mode and self.mode == "P":
|
||||||
# determine default mode
|
# determine default mode
|
||||||
if self.palette:
|
if self.palette:
|
||||||
mode = self.palette.mode
|
mode = self.palette.mode
|
||||||
else:
|
else:
|
||||||
mode = "RGB"
|
mode = "RGB"
|
||||||
|
if mode == "RGB" and has_transparency:
|
||||||
|
mode = "RGBA"
|
||||||
if not mode or (mode == self.mode and not matrix):
|
if not mode or (mode == self.mode and not matrix):
|
||||||
return self.copy()
|
return self.copy()
|
||||||
|
|
||||||
has_transparency = self.info.get("transparency") is not None
|
|
||||||
if matrix:
|
if matrix:
|
||||||
# matrix conversion
|
# matrix conversion
|
||||||
if mode not in ("L", "RGB"):
|
if mode not in ("L", "RGB"):
|
||||||
|
|
Loading…
Reference in New Issue
Block a user