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

Broken Map Plugin #117

Closed
jeremiah-k opened this issue Dec 24, 2024 · 2 comments
Closed

Broken Map Plugin #117

jeremiah-k opened this issue Dec 24, 2024 · 2 comments
Labels
bug Something isn't working

Comments

@jeremiah-k
Copy link
Collaborator

jeremiah-k commented Dec 24, 2024

GPT4o's rundown of the problem:

Background

  • The plugin uses the staticmaps library to render maps with text labels.
  • After upgrading to Pillow 10.0.0 or later, the textsize() method, which calculates the size of a text string, was deprecated and removed.
  • The staticmaps library relies on textsize() in its pillow_renderer.py file, which causes the AttributeError when the plugin is executed.

Steps Taken

Identified the Root Cause:
  • The error was traced to the staticmaps/pillow_renderer.py file, specifically in the render_attribution function.
  • The issue is caused by the use of the now-removed textsize() method in Pillow.

Proposed Fix:

A monkeypatch can restore the textsize() method dynamically by wrapping the textbbox() method. This allows existing code to continue functioning without directly modifying the staticmaps library.

import PIL.ImageDraw

def textsize(self, text, font=None, *args, **kwargs):
    bbox = self.textbbox((0, 0), text, font=font, *args, **kwargs)
    width = bbox[2] - bbox[0]
    height = bbox[3] - bbox[1]
    return width, height

# Apply the monkeypatch
PIL.ImageDraw.ImageDraw.textsize = textsize

This patch restores textsize() functionality dynamically at runtime, enabling compatibility with Pillow 10.0.0 or later while keeping the staticmaps library unchanged.

Current Situation

  • The plugin is functional except for the error in the staticmaps library.
  • The monkeypatch fix reintroduces textsize() dynamically and avoids modifying staticmaps directly.
  • Applying this patch should allow the plugin to work correctly with Pillow 10.0.0 or later.
@jeremiah-k jeremiah-k added the bug Something isn't working label Dec 24, 2024
@jeremiah-k
Copy link
Collaborator Author

jeremiah-k commented Dec 24, 2024

More map plugin-related details in the comments of this PR:
#116

I've subscribed to notifications for
flopp/py-staticmaps#39

and will update staticmaps when it becomes available and go from there.

@jeremiah-k
Copy link
Collaborator Author

I ended up getting it working.

Fixed by #118

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant