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

Save image #35

Closed
achourasia opened this Issue Jun 4, 2014 · 14 comments

Comments

Projects
None yet
10 participants
@achourasia
Copy link

achourasia commented Jun 4, 2014

Is there a way to save the image as PDF or PNG?
I am hoping to batch a set of datasets to create a set of image sequence for creating a video.

@nebulousdog

This comment has been minimized.

Copy link

nebulousdog commented Aug 18, 2014

Maybe try CutyCapt of the output path from the final create_map step.

path='my_map.html'
map.create_map(path)

Let me know of your solution! I'll be doing similar soon.

@nebulousdog

This comment has been minimized.

Copy link

nebulousdog commented Sep 19, 2014

So, I just did similar for my minecraft map, but it'll be the same process for you.

Install CutyCapt, see the install instructions for building, and there are instructions for running it headless online. Simplest is apt-get install cutycapt.

It is as simple as cutycapt --url=file:///home/user/project/goes/here/index.html --out=myoutput.png.

See cutycapt --help for zooming and turning javascript on or off, etc.

@wrobstory

This comment has been minimized.

Copy link
Contributor

wrobstory commented Sep 21, 2014

There's no easy way to do this outside of just doing a screen capture (right now).

@wrobstory wrobstory closed this Sep 21, 2014

@psychemedia

This comment has been minimized.

Copy link

psychemedia commented Dec 15, 2015

I've just come up with a recipe for doing this using selenium. For a folium map, m:

import os
import time
from selenium import webdriver

delay=5
fn='testmap.html'
tmpurl='file://{path}/{mapfile}'.format(path=os.getcwd(),mapfile=fn)
m.save(fn)

browser = webdriver.Firefox()
browser.get(tmpurl)
#Give the map tiles some time to load
time.sleep(delay)
browser.save_screenshot('map.png')
browser.quit()
@ocefpaf

This comment has been minimized.

Copy link
Member

ocefpaf commented Dec 15, 2015

@psychemedia that is very cool! It is also giving me some crazy ideas about continuous integration testing of maps. Thanks for sharing.

@chengjun

This comment has been minimized.

Copy link

chengjun commented Mar 20, 2016

  1. Open the generated html with chrome
  2. Print to save it as pdf,
  3. Open the pdf and export it as png or the other formats.
@carolinux

This comment has been minimized.

Copy link

carolinux commented Oct 24, 2016

This is how I did it within python (ie calling subprocess):

    import os
    import subprocess
    outdir = "screenshots" # this directory has to exist..
    map.save("tmp.html")
    url = "file://{}/tmp.html".format(os.getcwd())
    outfn = os.path.join(outdir,"outfig.png")
    subprocess.check_call(["cutycapt","--url={}".format(url), "--out={}".format(outfn)])

To save anybody else reading this some time:
*It wouldn't work if I passed the url as 'tmp.html', it needs to be a full path with file in front.
*Also, the filename where it's saved needs to end with .html

@xapple

This comment has been minimized.

Copy link

xapple commented Apr 13, 2017

In my experience cutycapt will render the map, but not any markers you have placed on it. Folium really needs a PDF or PNG output option.

@sergiolucero

This comment has been minimized.

Copy link

sergiolucero commented Apr 13, 2017

@ocefpaf

This comment has been minimized.

Copy link
Member

ocefpaf commented Apr 13, 2017

@sergiolucero do you fancy sending a PR to add that functionality to folium?

@oscarechobravo

This comment has been minimized.

Copy link

oscarechobravo commented Jun 9, 2017

@sergiolucero @ocefpaf Did a PR come from this? Trying to make comparable maps as subfigures, via an elegant solution for exporting to PDF or PNG.

@ocefpaf

This comment has been minimized.

Copy link
Member

ocefpaf commented Jun 9, 2017

@oscarechobravo no PR yet. Do you want to try it?

@ocefpaf ocefpaf referenced this issue Jun 24, 2017

Merged

PNG repr #634

@ocefpaf ocefpaf reopened this Jun 24, 2017

@ocefpaf

This comment has been minimized.

Copy link
Member

ocefpaf commented Jun 24, 2017

Finally done in #634

It is still experimental and feedback is welcome. Note that you'll need phantomjs installed to make it work.

@ocefpaf ocefpaf closed this Jun 24, 2017

@psychemedia

This comment has been minimized.

Copy link

psychemedia commented May 13, 2018

This looks like it could be handy for screenshotting, though again it uses a (Chrome) browser to grab the map image: https://github.com/wbkd/leaflet-mapshot

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment