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

Provide access to the pillow Image object used by export_png() and export_svg() #8262

Closed
monkut opened this issue Sep 20, 2018 · 1 comment
Closed

Comments

@monkut
Copy link
Contributor

monkut commented Sep 20, 2018

I'm using bokeh 0.13.0 with python 3.6 to auto-generate charts in AWS lambda periodically to send to Slack.

In order to achieve this I want to use bokeh.io.export_png() to export the generated chart to a PNG.
However, the AWS lambda environment is mostly read-only, and I would like to have direct access to the underlying image object used to save the '(png|svg)' so that I could write directly to a BytesIO() object instead of writing/reading to/from disk.

Currently, I've done a quick hack to allow this:

def export_png(obj, filename=None, height=None, width=None, webdriver=None, as_image=False):
    image = get_screenshot_as_png(obj, height=height, width=width, driver=webdriver)

    if filename is None:
        filename = default_filename("png")
    if as_image:
        return image
    else:
        image.save(filename)
        return abspath(filename)
@bryevdv
Copy link
Member

bryevdv commented Sep 20, 2018

That's not a hack, get_screenshot_as_png is the correct function to use if you want access to the image as an object.

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

No branches or pull requests

2 participants