Skip to content

Commit 5c7612c

Browse files
committed
fix for Pillow>=10.0
this will close File /opt/ros/noetic/share/jsk_perception/node_scripts/draw_rects.py, line 159, in draw_rects_callback img = put_text_to_image( File /opt/ros/noetic/lib/python3/dist-packages/jsk_recognition_utils/put_text.py, line 43, in put_text_to_image text_w, text_h = dummy_draw.textsize(text, font=pil_font) AttributeError: 'ImageDraw' object has no attribute 'textsize' when user install Pillow>=10.0 locally
1 parent 6ce2015 commit 5c7612c

File tree

1 file changed

+6
-1
lines changed
  • jsk_recognition_utils/python/jsk_recognition_utils

1 file changed

+6
-1
lines changed

jsk_recognition_utils/python/jsk_recognition_utils/put_text.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,12 @@ def put_text_to_image(
4040
text = text.decode('utf-8')
4141
pil_font = ImageFont.truetype(font=font_path, size=font_size)
4242
dummy_draw = ImageDraw.Draw(Image.new("RGB", (0, 0)))
43-
text_w, text_h = dummy_draw.textsize(text, font=pil_font)
43+
if hasattr(dummy_draw, 'textsize'):
44+
text_w, text_h = dummy_draw.textsize(text, font=pil_font)
45+
else: # Pillow>=10.0
46+
text_bbox = dummy_draw.textbbox((0,0), text, font=pil_font)
47+
text_w = text_bbox[2] - text_bbox[0]
48+
text_h = text_bbox[3] - text_bbox[1]
4449
text_bottom_offset = int(0.1 * text_h)
4550
x, y = pos
4651
if loc == 'top':

0 commit comments

Comments
 (0)