|
1 | 1 | import os, pixie, strformat, strutils |
2 | 2 |
|
| 3 | +var htmlEntries: seq[string] |
| 4 | + |
3 | 5 | proc xray*(image: Image, masterPath: string) = |
4 | 6 | let |
5 | 7 | generatedPath = "tmp/generated/" & masterPath |
6 | 8 | xrayPath = "tmp/xray/" & masterPath |
7 | 9 | createDir(generatedPath.splitPath.head) |
8 | 10 | createDir(xrayPath.splitPath.head) |
9 | 11 | image.writeFile(generatedPath) |
| 12 | + if not fileExists(masterPath): |
| 13 | + echo &"xray {masterPath} -> new master" |
| 14 | + createDir(masterPath.splitPath.head) |
| 15 | + image.writeFile(masterPath) |
| 16 | + return |
10 | 17 | let |
11 | 18 | master = readImage(masterPath) |
12 | 19 | (score, xRay) = diff(image, master) |
13 | 20 | xRay.writeFile(xrayPath) |
14 | 21 | echo &"xray {masterPath} -> {score:0.6f}" |
| 22 | + |
| 23 | + let bg = if score > 1: "#fee" else: "#fff" |
| 24 | + htmlEntries.add(&"""<div style="background:{bg};border:1px solid #ccc;padding:8px;break-inside:avoid"> |
| 25 | +<b>{masterPath}</b> score: {score:0.6f} |
| 26 | +<div style="display:flex;gap:8px;flex-wrap:wrap"> |
| 27 | +<div><div>Master</div><img src="../{masterPath}"></div> |
| 28 | +<div><div>Generated</div><img src="../{generatedPath}"></div> |
| 29 | +<div><div>Xray</div><img src="../{xrayPath}"></div> |
| 30 | +</div></div>""") |
| 31 | + |
| 32 | +proc writeReport*() = |
| 33 | + let html = """<!DOCTYPE html> |
| 34 | +<html><head><meta charset="utf-8"><title>Xray Report</title> |
| 35 | +<style>body{font-family:monospace;margin:16px}img{display:block;background:repeating-conic-gradient(#eee 0% 25%,#fff 0% 50%) 0 0/16px 16px}</style> |
| 36 | +</head><body> |
| 37 | +<h1>Xray Report</h1> |
| 38 | +""" & htmlEntries.join("\n") & "\n</body></html>" |
| 39 | + createDir("tmp") |
| 40 | + writeFile("tmp/xray_report.html", html) |
| 41 | + echo "Wrote tmp/xray_report.html" |
0 commit comments