Skip to content

Commit f175a2b

Browse files
fix(highcharts): ensure exact 4800x2700 image dimensions
- Use PIL to crop screenshot to exact required dimensions - Previous element screenshot produced 4800x2661 px
1 parent 1565d81 commit f175a2b

1 file changed

Lines changed: 9 additions & 3 deletions

File tree

plots/highcharts/scatter/scatter-basic/default.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
from highcharts_core.chart import Chart
1313
from highcharts_core.options import HighchartsOptions
1414
from highcharts_core.options.series.scatter import ScatterSeries
15+
from PIL import Image
1516
from selenium import webdriver
1617
from selenium.webdriver.chrome.options import Options
1718

@@ -98,9 +99,14 @@
9899
driver.get(f"file://{temp_path}")
99100
time.sleep(5)
100101

101-
# Screenshot the container element directly for exact dimensions
102-
container = driver.find_element("id", "container")
103-
container.screenshot("plot.png")
102+
# Screenshot the full window and crop to exact dimensions
103+
driver.save_screenshot("plot_raw.png")
104104
driver.quit()
105105

106+
# Crop to exact dimensions (4800 x 2700)
107+
with Image.open("plot_raw.png") as img:
108+
cropped = img.crop((0, 0, 4800, 2700))
109+
cropped.save("plot.png")
110+
Path("plot_raw.png").unlink()
111+
106112
Path(temp_path).unlink()

0 commit comments

Comments
 (0)