File: side_by_side_images.py

package info (click to toggle)
rdkit 202503.1-5
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 220,160 kB
  • sloc: cpp: 399,240; python: 77,453; ansic: 25,517; java: 8,173; javascript: 4,005; sql: 2,389; yacc: 1,565; lex: 1,263; cs: 1,081; makefile: 580; xml: 229; fortran: 183; sh: 105
file content (60 lines) | stat: -rwxr-xr-x 1,851 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#!/usr/bin/env python
# quick script for comparing SVGs in 2 different directories.
import argparse
import glob
from pathlib import Path

parser = argparse.ArgumentParser(description='Make an HTML table for comparing images.')
parser.add_argument('--dir1', required=True, help='Name of first directory.')
parser.add_argument('--dir2', required=True, help='Name of second directory.')
parser.add_argument('--file-glob', required=True, help='glob for files in first directory')
parser.add_argument('--outfile', default='side_by_side.html', help='Name of HTML file')

args = parser.parse_args()

d1 = args.dir1
d2 = args.dir2

if not Path(d1).exists():
    print(f'Directory {d1} missing.')
    exit(1)
if not Path(d2).exists():
    print(f'Directory {d2} missing.')
    exit(1)

with open(args.outfile, 'w') as f:
    f.write(f'''<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <meta http-equiv="X-UA-Compatible" content="ie=edge" />
    <title>{d1} vs {d2}</title>
    <link href="index.css" rel="stylesheet" />
  </head>
  <body style="background-color:#eeeeee;">
    <table border="1">
      <tr>
        <td></td>
        <td>{d1}</td>
        <td>{d2}</td>
      </tr>\n''')

    inglob = Path(d1)
    fns = [Path(fn) for fn in inglob.glob(args.file_glob)]
    fns.sort(key=lambda f: f.stat().st_mtime, reverse=True)

    for fp in fns:
        fn = fp.name
        if not fn.endswith('.svg') and not fn.endswith('.png'):
            continue
        fns = fn.replace('.svg', '')
        f.write(f'''      <tr>
        <td>{fns}</td>
        <td><span style="float:right"><img src="{d1}/{fn}" alt="{fns}"/></span></td>
        <td><img src="{d2}/{fn}" alt="{fns}"/></td>
        </tr>\n''')

    f.write('''    </table>
  </body>
</html>\n''')