diff --git a/Tests/images/standard_embedded_multiline_centered.png b/Tests/images/standard_embedded_multiline_centered.png new file mode 100644 index 000000000..3aebe3779 Binary files /dev/null and b/Tests/images/standard_embedded_multiline_centered.png differ diff --git a/Tests/test_imagefont.py b/Tests/test_imagefont.py index 16da87d46..f3cf3d880 100644 --- a/Tests/test_imagefont.py +++ b/Tests/test_imagefont.py @@ -960,6 +960,21 @@ class TestImageFont: assert_image_similar_tofile(im, "Tests/images/standard_embedded.png", 6.2) + def test_multiline_centered_embedded_color(self): + txt = "Hello\nWorld!" + ttf = ImageFont.truetype(FONT_PATH, 40, layout_engine=self.LAYOUT_ENGINE) + ttf.getbbox(txt) + + im = Image.new("RGB", (160, 96), "white") + d = ImageDraw.Draw(im) + d.multiline_text( + (10, 10), txt, font=ttf, fill="#fa6", align="center", embedded_color=True + ) + + assert_image_similar_tofile( + im, "Tests/images/standard_embedded_multiline_centered.png", 6.2 + ) + def test_cbdt(self): try: font = ImageFont.truetype( diff --git a/src/PIL/ImageDraw.py b/src/PIL/ImageDraw.py index e84dafb12..9b852fbcd 100644 --- a/src/PIL/ImageDraw.py +++ b/src/PIL/ImageDraw.py @@ -482,6 +482,7 @@ class ImageDraw: # extract mask and set text alpha color, mask = mask, mask.getband(3) color.fillband(3, (ink >> 24) & 0xFF) + coord = tuple(int(c) for c in coord) coord2 = coord[0] + mask.size[0], coord[1] + mask.size[1] self.im.paste(color, coord + coord2, mask) else: