-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapng
executable file
·41 lines (33 loc) · 989 Bytes
/
apng
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#!/usr/bin/env python3
"""
CLI tool for splitting and joining animated PNGS (APNG)
requires: pip install click apng
license: GPLv3+
author: [email protected]
"""
import click
from apng import PNG, APNG
@click.group()
def main():
"""split/join APNG files to PNG"""
pass
@main.command('split')
@click.argument('file', type=click.File('rb'))
def cmd_split(file):
"""split APNG file into multiple PNG files"""
filename = file.name
im = APNG.from_bytes(file.read())
for i, (png, control) in enumerate(im.frames):
with open(filename.replace('.png', f"_{i}.png"), 'wb') as f:
f.write(png.to_bytes())
@main.command('join')
@click.argument('filename')
@click.argument('files', type=click.File('rb'), nargs=-1)
def cmd_join(filename, files):
"""split APNG file into multiple PNG files"""
im = APNG()
for file in files:
im.append(PNG.from_bytes(file.read()))
im.save(filename)
if __name__ == "__main__":
main()