Skip to content

Instantly share code, notes, and snippets.

@eduardoleon
Last active March 14, 2024 13:39
Show Gist options
  • Save eduardoleon/082f5cdfddde00b715bf3e746678f673 to your computer and use it in GitHub Desktop.
Save eduardoleon/082f5cdfddde00b715bf3e746678f673 to your computer and use it in GitHub Desktop.
M9 flexing
#!/usr/bin/python
import os
import subprocess
import sys
ssdir = os.path.expanduser('~/arknights/ss')
m9dir = os.path.expanduser('~/arknights/m9')
p6dir = os.path.expanduser('~/arknights/p6')
def extract(sourcedir, targetdir, crop):
_, _, files = next(os.walk(sourcedir))
files.sort()
for (index, name) in enumerate(files):
source = f'{sourcedir}/{name}'
target = f'{targetdir}/{index:02d}.jpg'
args = ['convert', source, '-crop', crop, target]
subprocess.run(args)
def grid(targetdir, rows, cols):
slow = ['convert', '-append']
for i in range(rows):
fast = ['convert', '+append']
for j in range(i*cols, (i+1)*cols):
source = f'{targetdir}/{j:02d}.jpg'
fast.append(source)
target = f'{targetdir}/row-{i:02d}.jpg'
slow.append(target)
fast.append(target)
subprocess.run(fast)
slow.append(f'{targetdir}/grid.jpg')
subprocess.run(slow)
if __name__ == '__main__':
match (sys.argv[1], sys.argv[2]):
case ('e', 'm9'):
extract(ssdir, m9dir, '375x115+1240+330')
case ('e', 'p6'):
extract(ssdir, p6dir, '375x180+1240+265')
case ('g', 'm9'):
rows = int(sys.argv[3])
cols = int(sys.argv[4])
grid(m9dir, rows, cols)
case ('g', 'p6'):
rows = int(sys.argv[3])
cols = int(sys.argv[4])
grid(p6dir, rows, cols)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment