mirror of
https://github.com/python-pillow/Pillow.git
synced 2024-12-26 09:56:17 +03:00
Merge pull request #3719 from radarhere/p_rgb_rgba
Allow RGB and RGBA values for new P images
This commit is contained in:
commit
adbe97594e
|
@ -522,6 +522,16 @@ class TestImage(PillowTestCase):
|
|||
_make_new(im, blank_p, ImagePalette.ImagePalette())
|
||||
_make_new(im, blank_pa, ImagePalette.ImagePalette())
|
||||
|
||||
def test_p_from_rgb_rgba(self):
|
||||
for mode, color in [
|
||||
("RGB", '#DDEEFF'),
|
||||
("RGB", (221, 238, 255)),
|
||||
("RGBA", (221, 238, 255, 255))
|
||||
]:
|
||||
im = Image.new("P", (100, 100), color)
|
||||
expected = Image.new(mode, (100, 100), color)
|
||||
self.assert_image_equal(im.convert(mode), expected)
|
||||
|
||||
def test_no_resource_warning_on_save(self):
|
||||
# https://github.com/python-pillow/Pillow/issues/835
|
||||
# Arrange
|
||||
|
|
|
@ -2371,7 +2371,14 @@ def new(mode, size, color=0):
|
|||
from . import ImageColor
|
||||
color = ImageColor.getcolor(color, mode)
|
||||
|
||||
return Image()._new(core.fill(mode, size, color))
|
||||
im = Image()
|
||||
if mode == "P" and \
|
||||
isinstance(color, (list, tuple)) and len(color) in [3, 4]:
|
||||
# RGB or RGBA value for a P image
|
||||
from . import ImagePalette
|
||||
im.palette = ImagePalette.ImagePalette()
|
||||
color = im.palette.getcolor(color)
|
||||
return im._new(core.fill(mode, size, color))
|
||||
|
||||
|
||||
def frombytes(mode, size, data, decoder_name="raw", *args):
|
||||
|
|
Loading…
Reference in New Issue
Block a user