cmd/grayscale.py

22 lines
791 B
Python
Raw Normal View History

2020-06-17 20:43:25 +00:00
import PIL.Image
import sys
from voussoirkit import pathclass
from voussoirkit import pipeable
from voussoirkit import winglob
def main(argv):
for pattern in pipeable.go(argv, strip=True, skip_blank=True):
filenames = winglob.glob(pattern)
for filename in filenames:
filename = pathclass.Path(filename)
if filename.replace_extension('').basename.endswith('_gray'):
continue
new_filename = filename.replace_extension('').absolute_path + '_gray' + filename.dot_extension
print(f'{filename.basename} -> {new_filename.basename}')
image = PIL.Image.open(filename.absolute_path).convert('LA')
image.save(new_filename)
if __name__ == '__main__':
raise SystemExit(main(sys.argv[1:]))