Add imagesequence_to_images.
This commit is contained in:
parent
ea04f8415c
commit
7395935b8f
1 changed files with 41 additions and 0 deletions
41
imagesequence_to_images.py
Normal file
41
imagesequence_to_images.py
Normal file
|
@ -0,0 +1,41 @@
|
|||
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(sys.argv[1])
|
||||
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',
|
||||
)
|
||||
parser.set_defaults(func=imagesequence_to_images_argparse)
|
||||
|
||||
return betterhelp.go(parser, argv)
|
||||
|
||||
if __name__ == '__main__':
|
||||
raise SystemExit(main(sys.argv[1:]))
|
Loading…
Reference in a new issue