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

how to save Python-highcharts .html to image #85

Open
nankaimy opened this issue Dec 17, 2021 · 1 comment
Open

how to save Python-highcharts .html to image #85

nankaimy opened this issue Dec 17, 2021 · 1 comment

Comments

@nankaimy
Copy link

how to save Python-highcharts result .html to image

@ashokMafiree
Copy link

driver.get('data:text/html;charset=utf-8,' +chart.htmlcontent)

Get the dimensions of the chart container

chart_container = driver.find_element(By.ID, 'container')
chart_width = chart_container.size['width']
chart_height = chart_container.size['height']

Take a screenshot of the chart

screenshot = driver.get_screenshot_as_png()
screenshot_image = Image.open(BytesIO(screenshot))

Crop the screenshot to the dimensions of the chart

left = chart_container.location['x']
top = chart_container.location['y']
right = left + chart_width
bottom = top + chart_height
chart_image = screenshot_image.crop((left, top, right, bottom))

Save the chart image to a file

chart_image.save('chart.png')

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

No branches or pull requests

2 participants