-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathimagesequence_to_images.py
More file actions
42 lines (35 loc) · 1.29 KB
/
Copy pathimagesequence_to_images.py
File metadata and controls
42 lines (35 loc) · 1.29 KB
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
42
import argparse
import PIL.Image
import PIL.ImageSequence
import sys
from voussoirkit import betterhelp
from voussoirkit import pathclass
from voussoirkit import pipeable
from voussoirkit import vlogging
log = vlogging.getLogger(__name__, 'imagesequence_to_images')
def imagesequence_to_images_argparse(args):
for input_file in pathclass.glob_many_files(args.input_files):
input_file = pathclass.Path(input_file)
basename = input_file.replace_extension('').basename
input_image = PIL.Image.open(input_file.absolute_path)
for (index, image) in enumerate(PIL.ImageSequence.Iterator(input_image)):
this_png = input_file.parent.with_child(f'{basename}_{index+1:04d}.png')
pipeable.stdout(this_png.absolute_path)
image.save(this_png.absolute_path)
return 0
@vlogging.main_decorator
def main(argv):
parser = argparse.ArgumentParser(
description='''
Some file formats like TIFF can contain multiple images. This program
extracts them to separate PNG files.
''',
)
parser.add_argument(
'input_files',
nargs='+',
)
parser.set_defaults(func=imagesequence_to_images_argparse)
return betterhelp.go(parser, argv)
if __name__ == '__main__':
raise SystemExit(main(sys.argv[1:]))