fix drawing text alpha on RGBA image on big-endian platforms

This commit is contained in:
Nulano 2023-11-27 16:42:45 +01:00
parent f3b3442c50
commit 0cef9f251c
3 changed files with 4 additions and 2 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 364 B

After

Width:  |  Height:  |  Size: 387 B

View File

@ -862,7 +862,7 @@ def test_bitmap_blend(layout_engine, embedded_color):
"Tests/fonts/EBDTTestFont.ttf", size=64, layout_engine=layout_engine
)
im = Image.new("RGB", (128, 96), "white")
im = Image.new("RGBA", (128, 96), "white")
d = ImageDraw.Draw(im)
d.text((16, 16), "AA", font=font, embedded_color=embedded_color, fill="#8E2F52")

View File

@ -32,6 +32,7 @@
import math
import numbers
import struct
from . import Image, ImageColor
@ -542,7 +543,8 @@ class ImageDraw:
# font.getmask2(mode="RGBA") returns color in RGB bands and mask in A
# extract mask and set text alpha
color, mask = mask, mask.getband(3)
color.fillband(3, (ink >> 24) & 0xFF)
ink_alpha = struct.pack("=i", ink)[3]
color.fillband(3, ink_alpha)
x, y = coord
self.im.paste(color, (x, y, x + mask.size[0], y + mask.size[1]), mask)
else: