Skip to content

Commit 89c4a25

Browse files
committed
Create 0005.py
1 parent 6e1144f commit 89c4a25

1 file changed

Lines changed: 22 additions & 0 deletions

File tree

Liez-python-code/0005/0005.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
from PIL import Image
2+
import glob, os
3+
4+
def resize():
5+
for files in glob.glob('*.jpg'):
6+
filepath,filename = os.path.split(files) #分割文件名和路径名
7+
fname,fext = os.path.splitext(filename)
8+
im = Image.open(files)
9+
w,h = im.size
10+
if w > 640:
11+
x = w/640.0
12+
w = 640
13+
h = int(h/x)
14+
if h>1136:
15+
x = h/1136.0
16+
h = 1136
17+
w = int(w/x)
18+
print(w, h)
19+
im0 = im.resize((w,h),Image.ANTIALIAS)
20+
im0.save('0005'+filename)
21+
22+
resize()

0 commit comments

Comments
 (0)