Reputation: 7536
Given a saved HTML file with an image (an output from Bokeh), how can I save it as a PNG file with a DPI of 300?
I found some answers to similar questions, but they don't seem to work for me. I think I need someone to explain the whole process (importing the needed package, where it needs to be located if applicable, and how to call it).
I've tried this after pip installing webkit2png:
import os
os.system("webkit2png" "texas.html")
I've also tried:
import subprocess
subprocess.call("webkit2png", "texas.html")
Thanks in advance!
Upvotes: 5
Views: 12104
Reputation: 536
As of Bokeh 0.12.6
, it is now possible to export PNG and SVG directly from
Python code.
Exporting PNGs looks like this
export_png(plot, filename="plot.png")
And exporting SVGs looks like this
plot.output_backend = "svg"
export_svgs(plot, filename="plot.svg")
There are some optional dependencies that need to be installed. You can find more information in the Exporting Plots section of the User Guide.
Currently, plots are saved at their native resolution, but in 0.12.7
you will be able to set the size.
Upvotes: 8
Reputation: 467
There's no such thing as an "HTML image." HTML enables one to incorporate image files of various types within an HTML document, which a Web browser knows how to display and process.
Run your Bokeh (?) code and use a commercial screen capture utility (I like SnagIt!, which is FREE). That gives you the capability of saving out the image to disk in a wide array of formats (JPEG, TIF, PNG, GIF, etc.).
Upvotes: -4