Browse Source

initial meow

main
xenua 1 year ago
commit
cea2eee75d
Signed by: xenua
GPG Key ID: 8F93B68BD37255B8
  1. 3
      .gitmodules
  2. 48
      crop_rm2_image.py
  3. 1
      reSnap
  4. 26
      rm2shot

3
.gitmodules vendored

@ -0,0 +1,3 @@
[submodule "reSnap"]
path = reSnap
url = https://github.com/cloudsftp/reSnap.git

48
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)

1
reSnap

@ -0,0 +1 @@
Subproject commit c419c169a0fe52c54453f752fb092029084825c6

26
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"
Loading…
Cancel
Save