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

Replace deprecated Imagefont.getsize method #42

Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions visualkeras/layered.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,8 @@ def layered_view(model, to_file: str = None, min_z: int = 20, min_xy: int = 20,
if font is None:
font = ImageFont.load_default()

text_height = font.getsize("Ag")[1]
_, top, _, bottom = font.getbbox("Ag")
text_height = bottom - top
cube_size = text_height

de = 0
Expand All @@ -196,8 +197,9 @@ def layered_view(model, to_file: str = None, min_z: int = 20, min_xy: int = 20,

for layer_type in layer_types:
label = layer_type.__name__
text_size = font.getsize(label)
label_patch_size = (cube_size + de + spacing + text_size[0], cube_size + de)
left, _, right, _ = font.getbbox(label)
text_size = right - left
label_patch_size = (cube_size + de + spacing + text_size, cube_size + de)
# this only works if cube_size is bigger than text height

img_box = Image.new('RGBA', label_patch_size, background_fill)
Expand Down