From 04d109f904eb164625a1773da34bcbb98e2f76f4 Mon Sep 17 00:00:00 2001 From: neingeist Date: Wed, 7 Feb 2024 00:49:09 +0100 Subject: [PATCH] =?UTF-8?q?=F0=9F=9A=A7=20chop-edges:=20Chop=20edges=20of?= =?UTF-8?q?=20given=20image?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- chop-edges | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100755 chop-edges diff --git a/chop-edges b/chop-edges new file mode 100755 index 0000000..a56c598 --- /dev/null +++ b/chop-edges @@ -0,0 +1,31 @@ +#!/usr/bin/python3 +import click +import subprocess +from pathlib import Path + + +@click.command +@click.option("--top", default=0) +@click.option("--bottom", default=0) +@click.option("--left", default=0) +@click.option("--right", default=0) +@click.argument("image", type=click.Path(exists=True, dir_okay=False, path_type=Path), required=True) +def chop(top, bottom, left, right, image): + """ + Chop edges of the given image. + + Meant to be used with an auto-reloading image viewer on the output image. + """ + image_out = image.stem + ".out" + image.suffix + print(image_out) + subprocess.run([ + "convert", + image, + "-gravity", "North", "-chop", f"0x{top}", + "-gravity", "South", "-chop", f"0x{bottom}", + "-gravity", "West", "-chop", f"{left}x0", + "-gravity", "East", "-chop", f"{right}x0", + image_out], check=True) + +if __name__ == "__main__": + chop()