py-staticmaps icon indicating copy to clipboard operation
py-staticmaps copied to clipboard

Pillow-based drawing broken with Python 3.11

Open marph91 opened this issue 9 months ago • 6 comments

Traceback:

Traceback (most recent call last):
  File "...", line 19, in <module>
    image = context.render_pillow(800, 500)
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/martin/anaconda/envs/py311/lib/python3.11/site-packages/staticmaps/context.py", line 153, in render_pillow
    renderer.render_attribution(self._tile_provider.attribution())
  File "/home/martin/anaconda/envs/py311/lib/python3.11/site-packages/staticmaps/pillow_renderer.py", line 100, in render_attribution
    _, th = self.draw().textsize(attribution)
            ^^^^^^^^^^^^^^^^^^^^
AttributeError: 'ImageDraw' object has no attribute 'textsize'

Background: textsize was removed. See https://stackoverflow.com/a/77074371/7410886.

marph91 avatar May 05 '24 10:05 marph91

I believe this may have been fixed in 0.5.0, but that release isn't on pypi yet: https://pypi.org/project/py-staticmaps/#history

pamelafox avatar May 06 '24 16:05 pamelafox

@pamelafox true. Unfortunately, I've lost access to pypi - but I'm in the process of account recovery

flopp avatar May 09 '24 06:05 flopp

@pamelafox true. Unfortunately, I've lost access to pypi - but I'm in the process of account recovery

Any success with this already?

dc-buettgenbach avatar May 21 '24 16:05 dc-buettgenbach

For anyone looking for a workaround, add this before calling render_pillow():

import PIL.ImageDraw

def textsize(self: PIL.ImageDraw.ImageDraw, *args, **kwargs):
    x, y, w, h = self.textbbox((0, 0), *args, **kwargs)
    return w, h

# Monkeypatch fix for https://github.com/flopp/py-staticmaps/issues/39
PIL.ImageDraw.ImageDraw.textsize = textsize

Remboooo avatar Aug 02 '24 08:08 Remboooo

For anyone looking for a workaround, add this before calling render_pillow():

import PIL.ImageDraw

def textsize(self: PIL.ImageDraw.ImageDraw, *args, **kwargs):
    x, y, w, h = self.textbbox((0, 0), *args, **kwargs)
    return w, h

# Monkeypatch fix for https://github.com/flopp/py-staticmaps/issues/39
PIL.ImageDraw.ImageDraw.textsize = textsize

Thank you. Thank you very much!

hparlak avatar Aug 20 '24 08:08 hparlak