We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 456ba7d commit dc6988dCopy full SHA for dc6988d
1 file changed
chris5641/0005/ChangeResolution.py
@@ -0,0 +1,22 @@
1
+# -*- coding: utf-8 -*-
2
+"""
3
+第 0005 题:你有一个目录,装了很多照片,把它们的尺寸变成都不大于 iPhone5 分辨率的大小。
4
5
+from PIL import Image
6
+import os
7
+
8
+__author__ = 'Chris5641'
9
10
11
+def change_resolution(path):
12
+ for picname in os.listdir(path):
13
+ picpath = os.path.join(path, picname)
14
+ with Image.open(picpath) as im:
15
+ w, h = im.size
16
+ n = w/1366 if (w/1366) >= (h/640) else h/640
17
+ im.thumbnail((w/n, h/n))
18
+ im.save('finish_'+picname.split('.')[0]+'.jpg', 'jpeg')
19
20
21
+if __name__ == '__main__':
22
+ change_resolution('/home/chris/pictures/123')
0 commit comments