Skip to content

Commit

Permalink
Replace deprecated Imagefont.getsize method
Browse files Browse the repository at this point in the history
  • Loading branch information
simon-isler committed Sep 20, 2023
1 parent cd169b8 commit 79c7fe9
Showing 1 changed file with 5 additions and 3 deletions.
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

0 comments on commit 79c7fe9

Please sign in to comment.