commit cea2eee75d43866c02ca38f753f5cdfd74ba64d7 Author: xenua Date: Sun Oct 15 16:37:26 2023 +0200 initial meow diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..20f4662 --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "reSnap"] + path = reSnap + url = https://github.com/cloudsftp/reSnap.git diff --git a/crop_rm2_image.py b/crop_rm2_image.py new file mode 100755 index 0000000..2cfc4a9 --- /dev/null +++ b/crop_rm2_image.py @@ -0,0 +1,48 @@ +#!/usr/bin/env python3 +import sys + +from PIL import Image, ImageOps +import numpy as np + + +if __name__ == '__main__': + assert len(sys.argv) in [2, 3], "Image path must be passed!" + print("argv is", sys.argv) + path = sys.argv[1] + invert = bool(int(sys.argv[2]) if len(sys.argv) > 2 else 0) + print("invert is", invert) + + # load image, discard alpha (if present) + img = Image.open(path).convert("RGB") + + # remove menu and indicators + data = np.array(img) + menu_is_open = (data[1816:64, 1816:64] == 0).all() + if menu_is_open: + # remove the entire menu, and the x in the top right corner + data[:, :120, :] = 255 + data[40:81, 1324:1364, :] = 255 + else: + # remove only the menu indicator circle + data[40:81, 40:81, :] = 255 + + # crop to the bounding box + img = Image.fromarray(data).convert("RGB") + bbox = ImageOps.invert(img).getbbox() + img = img.crop(bbox) + alpha_source = np.array(img.convert("RGBA")) + + if invert: + target_data = np.array(ImageOps.invert(img).convert("RGBA")) + else: + target_data = np.array(img.convert("RGBA")) + + # set alpha channel + + # copy inverted red channel to alpha channel, so that the background is transparent + # (could have also used blue or green here, doesn't matter) + target_data[..., -1] = 255 - alpha_source[..., 0] + + img = Image.fromarray(target_data) + + img.save(path) diff --git a/reSnap b/reSnap new file mode 160000 index 0000000..c419c16 --- /dev/null +++ b/reSnap @@ -0,0 +1 @@ +Subproject commit c419c169a0fe52c54453f752fb092029084825c6 diff --git a/rm2shot b/rm2shot new file mode 100755 index 0000000..4420823 --- /dev/null +++ b/rm2shot @@ -0,0 +1,26 @@ +#!/bin/sh + +has_param() { + local term="$1" + shift + for arg; do + if [[ $arg == "$term" ]]; then + echo 1 + return + fi + done + echo 0 +} + +invert=$(has_param "-i" "$@") + +echo $invert + +tempdir=$(mktemp -d) +tempfile="${tempdir}/image.png" + +resnap -s rm2 -p -o $tempfile -n + +crop_rm2_image.py $tempfile $invert + +xclip -selection clipboard -t image/png -i "$tempfile"