Top-pad the shorter screenshot with white pixels so both PNGs share the same dimensions. Lets the comparison slider clip cleanly without the taller image bleeding past the divider.
(expected: Path, actual: Path)
| 460 | |
| 461 | |
| 462 | def _pad_screenshots_to_match(expected: Path, actual: Path) -> None: |
| 463 | """Top-pad the shorter screenshot with white pixels so both PNGs share |
| 464 | the same dimensions. Lets the comparison slider clip cleanly without the |
| 465 | taller image bleeding past the divider. |
| 466 | """ |
| 467 | from PIL import Image |
| 468 | |
| 469 | with Image.open(expected) as e_img, Image.open(actual) as a_img: |
| 470 | target_w = max(e_img.width, a_img.width) |
| 471 | target_h = max(e_img.height, a_img.height) |
| 472 | for path, img in ((expected, e_img), (actual, a_img)): |
| 473 | if img.width == target_w and img.height == target_h: |
| 474 | continue |
| 475 | canvas = Image.new("RGB", (target_w, target_h), "white") |
| 476 | canvas.paste(img.convert("RGB"), (0, 0)) |
| 477 | canvas.save(path) |
| 478 | |
| 479 | |
| 480 | def _write_review_page( |