diff --git a/to_png.py b/to_png.py index 83f15ea..667ad5e 100644 --- a/to_png.py +++ b/to_png.py @@ -10,7 +10,7 @@ pixel to fully transparent, and writes a PNG. Usage: python3 to_png.py [dir ...] # default: all gfx*_extracted dirs python3 to_png.py --key RRGGBB ... # custom colorkey (hex), default 000000 - python3 to_png.py --keep # keep .bmp files (default keeps them) + python3 to_png.py --keep # keep .bmp files (default deletes them) """ import sys, os, glob from PIL import Image @@ -30,6 +30,7 @@ def convert(path, key): def main(): args = sys.argv[1:] key = (0, 0, 0) + keep = False dirs = [] i = 0 while i < len(args): @@ -37,6 +38,8 @@ def main(): h = args[i+1].lstrip('#') key = (int(h[0:2], 16), int(h[2:4], 16), int(h[4:6], 16)) i += 2 + elif args[i] == '--keep': + keep = True; i += 1 else: dirs.append(args[i]); i += 1 if not dirs: @@ -47,6 +50,8 @@ def main(): for b in bmps: try: convert(b, key) + if not keep: + os.remove(b) total += 1 except Exception as ex: print(' ERROR %s: %s' % (b, ex)) @@ -54,4 +59,4 @@ def main(): print('TOTAL %d png (colorkey %02x%02x%02x)' % (total, *key)) if __name__ == '__main__': - main() + main() \ No newline at end of file