From f192d7c8ad628ea9952ef6bb508a9e11120acc52 Mon Sep 17 00:00:00 2001 From: brimoor Date: Tue, 2 Jan 2024 14:06:43 -0500 Subject: [PATCH 1/2] Font object has no attribute getsize --- eta/core/annotations.py | 13 +++++++++++-- setup.py | 2 +- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/eta/core/annotations.py b/eta/core/annotations.py index 05d902e6..b1165c8f 100644 --- a/eta/core/annotations.py +++ b/eta/core/annotations.py @@ -1663,7 +1663,7 @@ def _draw_bounding_box( # Title background if title_str: - textw, texth = font.getsize(title_str) + textw, texth = _get_text_size(font, title_str) bgtlx = boxtlx - linewidth + 1 bgbry = boxtly - linewidth + 1 bgbrx = bgtlx + textw + 2 * (label_text_pad_pixels + _DX) @@ -1912,8 +1912,17 @@ def _parse_hex_color(h): return rgb +def _get_text_size(font, string): + try: + _, _, w, h = font.getbbox(string) + except AttributeError: + w, h = font.getsize(string) # Pillow<8 + + return w, h + + def _compute_max_text_size(font, text_strs): - sizes = [font.getsize(s) for s in text_strs] + sizes = [_get_text_size(font, s) for s in text_strs] width, height = np.max(sizes, axis=0) return width, height diff --git a/setup.py b/setup.py index 96b92cab..268c36f9 100644 --- a/setup.py +++ b/setup.py @@ -16,7 +16,7 @@ from wheel.bdist_wheel import bdist_wheel -VERSION = "0.12.1" +VERSION = "0.12.2" class BdistWheelCustom(bdist_wheel): From 399af950e85633455a6a9af4ad8f16394e33d14b Mon Sep 17 00:00:00 2001 From: brimoor Date: Tue, 2 Jan 2024 14:10:19 -0500 Subject: [PATCH 2/2] cleanup --- eta/core/annotations.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/eta/core/annotations.py b/eta/core/annotations.py index b1165c8f..ca7370c6 100644 --- a/eta/core/annotations.py +++ b/eta/core/annotations.py @@ -1912,11 +1912,11 @@ def _parse_hex_color(h): return rgb -def _get_text_size(font, string): +def _get_text_size(font, text_str): try: - _, _, w, h = font.getbbox(string) + _, _, w, h = font.getbbox(text_str) except AttributeError: - w, h = font.getsize(string) # Pillow<8 + w, h = font.getsize(text_str) # Pillow<8 return w, h