From 947960bd99758fe72ad2723d2719d398dd7f84b9 Mon Sep 17 00:00:00 2001 From: Melon Bread Date: Mon, 30 Mar 2020 13:18:07 -0400 Subject: [PATCH] Added heic2png script --- .bin/heic2png.py | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100755 .bin/heic2png.py diff --git a/.bin/heic2png.py b/.bin/heic2png.py new file mode 100755 index 0000000..6ecfc9e --- /dev/null +++ b/.bin/heic2png.py @@ -0,0 +1,42 @@ +#!/usr/bin/env python3 +""" +Converts every HEIC image in a directory into a PNG image. +This script assumes you have `heif-convert` in your PATH +""" + +__author__ = "Melon Bread" +__version__ = "1.0.0" +__license__ = "MIT" + +import argparse +import os +import subprocess + +def main(args): + """ Main entry point of the app """ + working_directory = args.input + + for file in os.listdir(working_directory): + if file.upper().endswith('.HEIC'): + print(f'Converting {file}...') + subprocess.Popen(['heif-convert', file, f'{file[:-4]}png']).wait() + else: + print(f"Skipping {file}...") + + +if __name__ == "__main__": + """ This is executed when run from the command line """ + parser = argparse.ArgumentParser() + + # Required positional argument + parser.add_argument('-i', '--input', metavar='STRING', required=True, + help='The directory containing the HEIC image files') + + # Specify output of "--version" + parser.add_argument( + "--version", + action="version", + version="%(prog)s (version {version})".format(version=__version__)) + + args = parser.parse_args() + main(args)