Skip to content

Instantly share code, notes, and snippets.

@eduardoleon
Last active September 15, 2024 16:37
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
root = os.path.expanduser(f'~/arknights')
size = {
'm9': '375x115+1240+330',
'p6': '375x180+1240+265',
}
def do_work(kind, rows, cols):
path = f'{root}/{kind}'
_, _, files = next(os.walk(path))
files.sort()
images = iter(files)
args = ['magick']
for i in range(rows):
args.append('(')
for j in range(cols):
image = next(images, None)
if image:
args.append(f'{path}/{image}')
args.append('-crop')
args.append(size[kind])
else:
args.append('-size')
args.append(size[kind][:7])
args.append('canvas:gray')
args.append('+smush')
args.append('0')
args.append(')')
args.append('-smush')
args.append('0')
args.append(f'{path}.jpg')
subprocess.run(args)
if __name__ == '__main__':
kind = sys.argv[1]
rows = int(sys.argv[2])
cols = int(sys.argv[3])
do_work(kind, rows, cols)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment