-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpng_join
More file actions
executable file
·74 lines (55 loc) · 1.55 KB
/
png_join
File metadata and controls
executable file
·74 lines (55 loc) · 1.55 KB
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#! /usr/bin/env python3
import json
import shlex
import subprocess as sp
from pathlib import Path
from typing import List
import typer
from rich import print as echo
app = typer.Typer(pretty_exceptions_show_locals=False)
@app.command()
def main(
files: List[Path],
outfile: Path = "joined.pdf",
outfile_prefix: str = "plot_",
outfile_suffix: str = "pdf",
splice: int = 50,
pointsize: int = 20,
):
_outfiles = []
for ii, file in enumerate(files):
tag = str(file)
echo("... Tag:")
echo(tag)
if not file.exists():
echo(f"... {file} not found, skip")
continue
_outfile = f"{outfile_prefix}{ii:03d}.{outfile_suffix}"
cmd = f"convert {file} "
cmd += "-gravity South "
cmd += f"-pointsize {pointsize} "
cmd += f"-splice 0x{splice:d} "
cmd += f"-annotate +0+20 '{tag}' "
cmd += f"{_outfile}"
echo("... run:")
echo(cmd)
sp.run(shlex.split(cmd))
_outfiles.append(_outfile)
_cmd = "pdfjam "
for _outfile in _outfiles:
_cmd += f"{_outfile} '-' "
_cmd += "--no-tidy "
_cmd += "--landscape "
_cmd += f"--outfile {outfile}"
# check if files actually exist
for _file in _outfiles:
assert Path(_file).exists(), f"{_file} does not exist, arguments are folders!"
echo("... run:")
echo(_cmd)
sp.run(shlex.split(_cmd), check=True)
# cleanup
for _file in _outfiles:
Path(_file).unlink()
echo("done.")
if __name__ == "__main__":
app()