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 copyright/attribution message to downloaded map images #735

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

mmd-osm
Copy link
Contributor

@mmd-osm mmd-osm commented Feb 3, 2025

This PR introduces a new URL parameter attribution=X which adds OSM attribution to the map export, both for vector and raster formats. Besides, this PR adds webp image format.

Image

I introduced a new dependency on python3-pil package to enable the png->{webp,jpeg} conversion in "show attribution" mode. This might require further adjustments to https://github.com/openstreetmap/chef/blob/master/cookbooks/tile/recipes/default.rb#L102-L105, which aren't covered in this PR.

If attribution hasn't been requested, the code should behave exactly as before.

Fixes openstreetmap/openstreetmap-website#551

cookbooks/tile/templates/default/export.erb Outdated Show resolved Hide resolved
cookbooks/tile/templates/default/export.erb Show resolved Hide resolved
cookbooks/tile/templates/default/export.erb Outdated Show resolved Hide resolved
cookbooks/tile/templates/default/export.erb Outdated Show resolved Hide resolved
cookbooks/tile/templates/default/export.erb Outdated Show resolved Hide resolved
@mmd-osm
Copy link
Contributor Author

mmd-osm commented Feb 3, 2025

So regarding the temporary file vs. BytesIO topic. I looked at both options and thought it might be safer to store intermediate results on disk, rather than trying to juggle everything in memory. I also noticed the "resource.setrlimit" at the beginning and thought that memory usage is something to watch out for.

Are temporary files too much of a concern?

@tomhughes
Copy link
Member

The memory limit is mostly just a backstop against people doing stupid things, especially with the vector output formats as I recall.

Temporary files generally make me nervous because you need to be sure they will always get cleaned up properly, especially if like here you're not immediately deleting them, which you can't if you need to be able to pass them to functions by name. Though all the functions here could actually take a handle instead I think.

@mmd-osm mmd-osm force-pushed the feature/exportattribution branch from f796226 to 4b15ef9 Compare February 4, 2025 07:13
@pnorman
Copy link
Collaborator

pnorman commented Feb 4, 2025

memory usage is something to watch out for.

I suspect this is because Mapnik can get memory crazy with some output formats. The memory limit is 4GB, so I don't see that storing the rasterized output in-memory is an issue.

PDF and PS are terrible to use with Mapnik and likely to break stuff in other ways, so I wouldn't worry about those.

mmd-osm added a commit to mmd-osm/openstreetmap-website that referenced this pull request Feb 4, 2025
mmd-osm added a commit to mmd-osm/openstreetmap-website that referenced this pull request Feb 4, 2025
mmd-osm added a commit to mmd-osm/openstreetmap-website that referenced this pull request Feb 5, 2025
@@ -162,6 +162,7 @@
python3-pyotp
python3-pyproj
python3-setuptools
python3-pil
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we keep this list alphabetically ordered please?


if format == "png":
output_io.seek(0)
return output_io.read()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are we reading in the data rather than just returning the handle and letting the called use output_file on it? If you do that you don't need the seek either as output_file already does that.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The current raster code doesn’t use output_file either (but sys.stdout.buffer.write(image)). I wanted to keep the current code as is. Using output_code would require some attribution dependent logic in line 135. I’m not sure this is better.

image = mapnik.Image(map.width, map.height)
mapnik.render(map, image)

if attribution == 'X':
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are we making the attribution optional?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's suppose I want to put a static map image on my website. If the attribution is optional, I might export the image without an attribution, put it on my site and add a link to osm under it. If the attribution is not optional, I'll see that osm is already credited and I won't add a link.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That’s what the original issue openstreetmap/openstreetmap-website#551 was proposing. Maybe @simonpoole still remembers…

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

At the time my thoughts were that somebody putting the image on a website has ample ways of providing attribution, but somebody that was just printing it out would have to jump through hoops to add it.

But given that the audience is likely getting more unsophisticated by the day it is probably OK to simply always add it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

At least in openstreetmap/openstreetmap-website#5607 it’s enabled by default and users need to explicitly disable it.

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

Successfully merging this pull request may close these issues.

Downloaded map images do not have a copyright/attribution message
5 participants