MCPcopy Create free account
hub / github.com/idank/explainshell / _pad_screenshots_to_match

Function _pad_screenshots_to_match

tests/evals/render/render_eval.py:462–477  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

460
461
462def _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
480def _write_review_page(

Callers 1

diff_reportFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected