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

Save image #35

Closed
achourasia opened this issue Jun 4, 2014 · 16 comments
Closed

Save image #35

achourasia opened this issue Jun 4, 2014 · 16 comments

Comments

@achourasia
Copy link

@achourasia 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.

@dreamalligator
Copy link

@dreamalligator dreamalligator 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.

@dreamalligator
Copy link

@dreamalligator dreamalligator 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
Copy link
Contributor

@wrobstory 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
Copy link

@psychemedia 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
Copy link
Member

@ocefpaf 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
Copy link

@chengjun 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
Copy link

@carolinux 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
Copy link

@xapple 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
Copy link

@sergiolucero sergiolucero commented Apr 13, 2017

@ocefpaf
Copy link
Member

@ocefpaf ocefpaf commented Apr 13, 2017

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

@oscarechobravo
Copy link

@oscarechobravo 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
Copy link
Member

@ocefpaf ocefpaf commented Jun 9, 2017

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

@ocefpaf ocefpaf mentioned this issue Jun 24, 2017
@ocefpaf ocefpaf reopened this Jun 24, 2017
@ocefpaf
Copy link
Member

@ocefpaf 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
Copy link

@psychemedia 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

@laxatives
Copy link

@laxatives laxatives commented Jul 9, 2020

Could you please provide an example of usage instead of pointing to the raw PR? You're asking all of your users to read your work-in-progress code from 2 years ago and links to notebooks that don't exist when there should just be documentation provided for a feature like this.

@SatvikNema
Copy link

@SatvikNema SatvikNema commented Mar 19, 2021

Finally done in #634

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

@ocefpaf the notebook mentioned inside that pr doesn't exist anymore. Can you explain how this feature works?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet