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

Pillow-based drawing broken with Python 3.11 #39

Open
marph91 opened this issue May 5, 2024 · 6 comments
Open

Pillow-based drawing broken with Python 3.11 #39

marph91 opened this issue May 5, 2024 · 6 comments

Comments

@marph91
Copy link

marph91 commented May 5, 2024

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.

@pamelafox
Copy link

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

@flopp
Copy link
Owner

flopp commented May 9, 2024

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

@dc-buettgenbach
Copy link

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

Any success with this already?

@Remboooo
Copy link

Remboooo commented Aug 2, 2024

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

@hparlak
Copy link

hparlak commented Aug 20, 2024

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!

@arabovs
Copy link

arabovs commented Oct 24, 2024

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

have you recovered your key yet ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants