mirror of
https://github.com/python-pillow/Pillow.git
synced 2025-07-04 03:43:13 +03:00
fix drawing text alpha on RGBA image on big-endian platforms
This commit is contained in:
parent
f3b3442c50
commit
0cef9f251c
Binary file not shown.
Before Width: | Height: | Size: 364 B After Width: | Height: | Size: 387 B |
|
@ -862,7 +862,7 @@ def test_bitmap_blend(layout_engine, embedded_color):
|
||||||
"Tests/fonts/EBDTTestFont.ttf", size=64, layout_engine=layout_engine
|
"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 = ImageDraw.Draw(im)
|
||||||
d.text((16, 16), "AA", font=font, embedded_color=embedded_color, fill="#8E2F52")
|
d.text((16, 16), "AA", font=font, embedded_color=embedded_color, fill="#8E2F52")
|
||||||
|
|
||||||
|
|
|
@ -32,6 +32,7 @@
|
||||||
|
|
||||||
import math
|
import math
|
||||||
import numbers
|
import numbers
|
||||||
|
import struct
|
||||||
|
|
||||||
from . import Image, ImageColor
|
from . import Image, ImageColor
|
||||||
|
|
||||||
|
@ -542,7 +543,8 @@ class ImageDraw:
|
||||||
# font.getmask2(mode="RGBA") returns color in RGB bands and mask in A
|
# font.getmask2(mode="RGBA") returns color in RGB bands and mask in A
|
||||||
# extract mask and set text alpha
|
# extract mask and set text alpha
|
||||||
color, mask = mask, mask.getband(3)
|
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
|
x, y = coord
|
||||||
self.im.paste(color, (x, y, x + mask.size[0], y + mask.size[1]), mask)
|
self.im.paste(color, (x, y, x + mask.size[0], y + mask.size[1]), mask)
|
||||||
else:
|
else:
|
||||||
|
|
Loading…
Reference in New Issue
Block a user