diff options
author | Daniel Friesel <derf@finalrewind.org> | 2020-12-27 08:42:56 +0100 |
---|---|---|
committer | Daniel Friesel <derf@finalrewind.org> | 2020-12-27 08:42:56 +0100 |
commit | 422153e18d7e0e4f5e3aab94eb4d05072ce21939 (patch) | |
tree | 2384d521a5534b0553211668e33c60d371725e03 /lib | |
parent | 13a6832bb4f9ec68d26ae59c8dd1260279e3e70a (diff) |
add svg export
Diffstat (limited to 'lib')
-rwxr-xr-x | lib/export-carriage.py | 57 |
1 files changed, 34 insertions, 23 deletions
diff --git a/lib/export-carriage.py b/lib/export-carriage.py index 69e5133..8f1e4e4 100755 --- a/lib/export-carriage.py +++ b/lib/export-carriage.py @@ -27,7 +27,7 @@ class SVGObject: ) -def main(infile, outfile): +def main(infile, *outfiles): ret = subprocess.run( ["inkscape", "--query-all", infile], capture_output=True, check=True ) @@ -56,34 +56,45 @@ def main(infile, outfile): x_positions = list() for o in objects: - if (o.is_path or o.is_tspan) and (o.y < crop_y_min or o.y_ > crop_y_max): + if (o.is_path() or o.is_tspan()) and (o.y < crop_y_min or o.y_ > crop_y_max): objects_to_delete.append(o.id) - elif o.is_path and o.y >= crop_y_min and o.y_ <= crop_y_max: - x_positions.append(o.x) - x_positions.append(o.x_) - - crop_x_min = int(np.min(x_positions)) - crop_x_max = int(np.max(x_positions)) + 1 objects_to_delete = ",".join(objects_to_delete) - export_area = f"--export-area={crop_x_min}:{crop_y_min}:{crop_x_max}:{crop_y_max}" select_objects = f"--select={objects_to_delete}" - subprocess.run( - [ - "xvfb-run", - "inkscape", - export_area, - select_objects, - "--verb=EditDelete", - "--batch-process", - "--export-dpi=600", - "-o", - outfile, - infile, - ] - ) + for outfile in outfiles: + if outfile.endswith(".png"): + subprocess.run( + [ + "xvfb-run", + "inkscape", + "--export-area-drawing", + select_objects, + "--verb=EditDelete", + "--batch-process", + "--export-dpi=600", + "-o", + outfile, + infile, + ] + ) + elif outfile.endswith(".svg"): + subprocess.run( + [ + "xvfb-run", + "inkscape", + "--export-area-drawing", + select_objects, + "--verb=EditDelete", + "--batch-process", + "-o", + outfile, + infile, + ] + ) + else: + raise RuntimeError(f"Unsupported export format: {outfile}") if __name__ == "__main__": |