Skip to content

Commit 3b2435f

Browse files
committed
update pillow
1 parent 61693a5 commit 3b2435f

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

examples/research_projects/anytext/anytext.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -723,10 +723,11 @@ def draw_glyph(self, font, text):
723723
ratio = min(W * 0.9 / text_width, H * 0.9 / text_height)
724724
new_font = font.font_variant(size=int(g_size * ratio))
725725

726-
text_width, text_height = new_font.getsize(text)
727-
offset_x, offset_y = new_font.getoffset(text)
726+
left, top, right, bottom = new_font.getbbox(text)
727+
text_width = right - left
728+
text_height = bottom - top
728729
x = (img.width - text_width) // 2
729-
y = (img.height - text_height) // 2 - offset_y // 2
730+
y = (img.height - text_height) // 2 - top // 2
730731
draw.text((x, y), text, font=new_font, fill="white")
731732
img = np.expand_dims(np.array(img), axis=2).astype(np.float64)
732733
return img

0 commit comments

Comments
 (0)