paulgavrikov/visualkeras

[BUG] Pillow 10.3.0 removed getsize() function so legend parameter do not work now

Closed this issue · 2 comments

Describe the bug
The title essentially explains it. Since Pillow was upgraded to version 10.x, the getsize() function has been removed. This raises an error when attempting to use the legend=True parameter, as it makes a call to getsize().

Minimal Code To Reproduce

import visualkeras
from PIL import ImageFont
font = ImageFont.truetype('/usr/share/fonts/truetype/Lato-Regular.ttf', 32)

visualkeras.layered_view(model, to_file='model.png', legend=True, font=font).show() # write to disk

Expected behavior
The ability to call the legend parameter without encountering any errors.

Screenshots
image

Environment (please complete the following information):

  • OS: Debian 12
  • Python: 3.9.19
  • Module Version: 0.0.2 for visualkeras and 10.3.0 for Pillow

Additional context
I've read that this issue can be easily fixed by using either getbbox() or getlength() for Pillow 10.x.x. However, I'm unsure how extensively the code needs to be modified to fully resolve it.

As far as I can see, themaster branch was updated three months ago to fix this problem.
There are two things you can do to solve your issue:

  1. Update the library using:
    pip install git+https://github.com/paulgavrikov/visualkeras
  2. Downgrade the Pillow version to 9.5.0
    pip install Pillow<=9.5.0

@edoardo-tam's answer is correct, marking this as resolved.
(will be updating pypi soon)