Merge pull request #3163 from radarhere/fillcolor

Fixed transform fillcolor argument when image mode is RGBA or LA
This commit is contained in:
Hugo 2018-06-14 09:25:00 +03:00 committed by GitHub
commit 48dda53c12
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 10 deletions

View File

@ -53,15 +53,20 @@ class TestImageTransform(PillowTestCase):
self.assert_image_equal(transformed, scaled) self.assert_image_equal(transformed, scaled)
def test_fill(self): def test_fill(self):
im = hopper('RGB') for mode, pixel in [
(w, h) = im.size ['RGB', (255, 0, 0)],
transformed = im.transform(im.size, Image.EXTENT, ['RGBA', (255, 0, 0, 255)],
(0, 0, ['LA', (76, 0)]
w*2, h*2), ]:
Image.BILINEAR, im = hopper(mode)
fillcolor='red') (w, h) = im.size
transformed = im.transform(im.size, Image.EXTENT,
(0, 0,
w*2, h*2),
Image.BILINEAR,
fillcolor='red')
self.assertEqual(transformed.getpixel((w-1, h-1)), (255, 0, 0)) self.assertEqual(transformed.getpixel((w-1, h-1)), pixel)
def test_mesh(self): def test_mesh(self):
# this should be a checkerboard of halfsized hoppers in ul, lr # this should be a checkerboard of halfsized hoppers in ul, lr

View File

@ -2115,11 +2115,11 @@ class Image(object):
if self.mode == 'LA': if self.mode == 'LA':
return self.convert('La').transform( return self.convert('La').transform(
size, method, data, resample, fill).convert('LA') size, method, data, resample, fill, fillcolor).convert('LA')
if self.mode == 'RGBA': if self.mode == 'RGBA':
return self.convert('RGBa').transform( return self.convert('RGBa').transform(
size, method, data, resample, fill).convert('RGBA') size, method, data, resample, fill, fillcolor).convert('RGBA')
if isinstance(method, ImageTransformHandler): if isinstance(method, ImageTransformHandler):
return method.transform(size, self, resample=resample, fill=fill) return method.transform(size, self, resample=resample, fill=fill)