5

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!

2 Answers 2

8

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.

Sign up to request clarification or add additional context in comments.

Comments

-4

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.).

1 Comment

Right. It's an HTML file with an image, as I elaborated in the actual question. I am trying to programmatically export to PNG or retrieve the file and convert its embedded image to PNG without having to open and click on anything.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.