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

add attribution / license to image #20

Open
Henner opened this issue Jul 1, 2019 · 1 comment
Open

add attribution / license to image #20

Henner opened this issue Jul 1, 2019 · 1 comment

Comments

@Henner
Copy link

Henner commented Jul 1, 2019

OSM images are only allowed to use, if you add a license hint:
https://www.openstreetmap.org/copyright/en

Can you please add a function for this?

@Henner Henner changed the title add attribution to image add attribution / license to image Jul 1, 2019
@Henner
Copy link
Author

Henner commented Jul 8, 2019

I did it like this:

class AttribStaticMap(StaticMap, object):
    def __init__(self, *args, **kwargs):
        self.attribution = u'© OpenStreetMap-Mitwirkende'
        super(AttribStaticMap, self).__init__(*args, **kwargs)

    def _draw_features(self, image):
        super(AttribStaticMap, self)._draw_features(image)

        txt = Image.new('RGBA', image.size, (255, 255, 255, 0))
        # get a font
        fnt = ImageFont.truetype('FreeMono.ttf', 12)
        # fnt = ImageFont.load_default()
        # get a drawing context
        d = ImageDraw.Draw(txt)

        textSize = fnt.getsize(self.attribution)
        textPosition = (image.size[0] - textSize[0], image.size[1] - textSize[1])
        offset = 2
        options = {'fill': (255, 255, 255, 180)}
        d.rectangle([(textPosition[0] - (2 * offset), textPosition[1] - (2 * offset)), (textSize[0] + textPosition[0] + (2 * offset), textSize[1] + textPosition[1] + (2 * offset))], **options)

        # draw text, full opacity
        d.text((textPosition[0] - offset, textPosition[1] - offset), self.attribution, font=fnt, fill='black')

        image.paste(txt, (0, 0), txt)

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

1 participant