-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathold.type1.py
37 lines (29 loc) · 945 Bytes
/
old.type1.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
import os
from PIL import Image
walk = os.walk('F:\\Download\\top\\')
for root,dirs,files in walk:
new_root = root.replace('top', 'newtop')
for d in dirs:
if not os.path.exists(new_root):
os.mkdir(new_root)
path = os.path.join(new_root,d)
#print(path)
if not os.path.exists(path):
os.mkdir(path)
for f in files:
oldpath = os.path.join(root,f)
newpath = os.path.join(new_root,f)
if os.path.exists(newpath):
try :
print('exists : %s' % newpath)
except UnicodeEncodeError as e:
print(e)
continue
sImage = Image.open(oldpath)
w,h = sImage.size
dImg = sImage.resize((int(w/2),int(h/2)), Image.ANTIALIAS)
dImg.save(newpath)
try :
print('convert : %s' % newpath)
except UnicodeEncodeError as e:
print(e)