-
Notifications
You must be signed in to change notification settings - Fork 63
/
psd.py
51 lines (37 loc) · 1.45 KB
/
psd.py
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
43
44
45
46
47
48
49
50
51
import argparse
import os
from psd_tools import PSDImage
def parse_args():
desc = "Tools to normalize an image dataset"
parser = argparse.ArgumentParser(description=desc)
parser.add_argument('-i','--input_folder', type=str,
default='./input/',
help='Directory path to the inputs folder. (default: %(default)s)')
parser.add_argument('-o','--output_folder', type=str,
default='./output/',
help='Directory path to the outputs folder. (default: %(default)s)')
parser.add_argument('-v','--verbose', action='store_true',
help='Print progress to console.')
args = parser.parse_args()
return args
def main():
global args
global inter
args = parse_args()
if not os.path.exists(args.output_folder):
os.makedirs(args.output_folder)
for root, subdirs, files in os.walk(args.input_folder):
files = [f for f in files if not f[0] == '.']
if(args.verbose): print('--\nroot = ' + root)
for subdir in subdirs:
if(args.verbose): print('\t- subdirectory ' + subdir)
for filename in files:
fn = os.path.splitext(filename)[0]
file_path = os.path.join(root, filename)
out_path = os.path.join(args.output_folder, (fn+'.png'))
if(args.verbose): print('\t- file %s (full path: %s)' % (filename, file_path))
psd = PSDImage.load(file_path)
psd.print_tree()
psd.as_PIL().save(out_path)
if __name__ == "__main__":
main()