Export_png yields low resolution / fuzzy / blurry image

Upon using export_png, I got lower resolution results than expected.

When I click the “save” button next to a Bokeh diagram, I get a nice rendering saved as a png. However, when I use the export_png function, I get a pretty low resolution image. This makes it hard to export many high quality images at once.

I initially expected this to be a configuration issue, and it partially was. There are settings you can pass to the WebDrivers (that run Selenium) to improve the resolution. Bokeh uses defaults that seem to increase the blur. However, after tuning these configuration options, I still experienced blur. It turns out that PIL’s Image.resize causes a fair amount of blur as well. I copied the existing get_screenshot_as_png function from Bokeh and removed the Image.resize call. That resulted in an image which seems indistinguishable from the image I get when I click the “save” button in Jupyter Notebook.

My work is here: https://github.com/logston/bokeh-webdriver-examples/blob/main/get_screenshot_as_img.ipynb

I’m writing this up to help my future self and anyone else that may encounter this issue.