def save_map(m: folium.Map, filename: str = '', render_time: int = 5) -> None: """ Wrapper to convert a folium map to .png and save itself. Warning: to install it, you need selenium (pip install selenium), and a browser specific executable. For firefox it is geckodriver. 1) download the latest version 2) make it executable: chmod +x geckodriver 3) move it where it needs to be : sudo mv geckodriver /usr/local/bin/ (adding the path to geckdriver to $PATH supposedly works too, but only the above worked for me). :param m: folium.Map, :param filename: str, path to save map as .png :param render_time: int, time to render as .png :return: None """ img_data = m._to_png(render_time) img = Image.open(io.BytesIO(img_data)) img.save(filename)
def export_as_png(map_object: Map): return map_object._to_png()