Export a folium map as a png
27,258
I use this:
... where m is my map object. And 5 is the time (seconds) to render the map.
import io
from PIL import Image
img_data = m._to_png(5)
img = Image.open(io.BytesIO(img_data))
img.save('image.png')
Author by
Mittenchops
Updated on July 19, 2022Comments
-
Mittenchops almost 2 years
I'm working with a map created using python, folium, and geojson, similar to this one.
However, instead of this image being an interactive HTML document, I would rather simply export it to png or svg.
Using the syntax:
m = folium.Map( # etc..) m.save("filename.png")
Saves a file, but it is still HTML, rather than png. What's the correct output command to render not-to-html?
-
jaromrax over 3 yearsIt requires SELENIUM. And thus webriver in path. Good that I have found this answer. If the selenium requirement was mentioned in the beginning, I wouldnt bother with folium.