From 3b725a1e480b54a7a3e526808d21f4eb5e384700 Mon Sep 17 00:00:00 2001
From: "veralara.bernhard" <veralara.bernhard@uzh.ch>
Date: Thu, 7 Mar 2024 15:53:08 +0100
Subject: [PATCH] Update for Pillow>=10.0.1
getsize() is deprecated and replaced with getbbox
---
src/layoutparser/visualization.py | 7 ++++++-
1 file changed, 6 insertions(+), 1 deletion(-)
diff --git a/src/layoutparser/visualization.py b/src/layoutparser/visualization.py
index 002d063..543c166 100644
--- a/src/layoutparser/visualization.py
+++ b/src/layoutparser/visualization.py
@@ -389,7 +389,12 @@ def draw_box(
text = str(ele.type) if not text else text + ": " + str(ele.type)
start_x, start_y = ele.coordinates[:2]
- text_w, text_h = font_obj.getsize(text)
+
+ # Compatibility with Pillow>=10.0.1
+ if hasattr(font_obj, 'getsize'):
+ text_w, text_h = font_obj.getsize(text)
+ else:
+ text_w, text_h = font_obj.getbbox(text)[2:4]
text_box_object = Rectangle(
start_x, start_y, start_x + text_w, start_y + text_h