Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Show Element Id when set to true breaks the code due to FreeTypeFont has no getsize attribute #194

Open
Extrosoph opened this issue Aug 23, 2023 · 2 comments
Labels
bug Something isn't working

Comments

@Extrosoph
Copy link

Describe the bug
I was trying to use show_element_id as True in draw_box but suddenly got an AttributeError: 'FreeTypeFont' object has no attribute 'getsize'

Checklist

  1. I have searched related issues but cannot get the expected help.
  2. The bug has not been fixed in the latest version, see the Layout Parser Releases

To Reproduce
Steps to reproduce the behavior:

  1. What command or script did you run?
lp.draw_box(pdf_images[4], text_blocks, box_width=3, show_element_id=True)  # Use the default font provided by the library

Environment

  1. Used on windows with jupyter lab on conda
  2. Using layoutparser version 0.3.4
  3. All other libraries has been installed

Error traceback
AttributeError Traceback (most recent call last)
Cell In[17], line 1
----> 1 lp.draw_box(pdf_images[4], text_blocks,
2 box_width=3, show_element_id=True) # Use the default font provided by the library

File ~\miniconda3\Lib\site-packages\layoutparser\visualization.py:194, in image_loader..wrap(canvas, layout, *args, **kwargs)
192 elif isinstance(canvas, np.ndarray):
193 canvas = Image.fromarray(canvas)
--> 194 out = func(canvas, layout, *args, **kwargs)
195 return out

File ~\miniconda3\Lib\site-packages\layoutparser\visualization.py:392, in draw_box(canvas, layout, box_width, box_alpha, box_color, color_map, show_element_id, show_element_type, id_font_size, id_font_path, id_text_color, id_text_background_color, id_text_background_alpha)
389 text = str(ele.type) if not text else text + ": " + str(ele.type)
391 start_x, start_y = ele.coordinates[:2]
--> 392 text_w, text_h = font_obj.getsize(text)
394 text_box_object = Rectangle(
395 start_x, start_y, start_x + text_w, start_y + text_h
396 )
397 # Add a small background for the text

AttributeError: 'FreeTypeFont' object has no attribute 'getsize'

Screenshots
image

@Extrosoph Extrosoph added the bug Something isn't working label Aug 23, 2023
@AIexanderDicke
Copy link

You can fix this issue by running pip install Pillow==9.5.0.

This happens because FreeTypeFont.getsize() has been deprecated in Version 10.0.0 of Pillow.

@estacy
Copy link

estacy commented Mar 8, 2024

Had the same issue and this solution worked for me. Thank you!

You can fix this issue by running pip install Pillow==9.5.0.

This happens because FreeTypeFont.getsize() has been deprecated in Version 10.0.0 of Pillow.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants