Skip to content

Commit 724248b

Browse files
committed
Complete 0005
1 parent 693b281 commit 724248b

File tree

3 files changed

+20
-0
lines changed

3 files changed

+20
-0
lines changed

DIYgod/0005/change_resolution.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# -*- coding: utf-8 -*-
2+
3+
from PIL import Image
4+
5+
def change_resolution(picPath, reslution):
6+
img = Image.open(picPath)
7+
x, y = img.size
8+
print x, y
9+
changex = float(x) / reslution[0]
10+
changey = float(y) / reslution[1]
11+
12+
# 判断分辨率是否满足
13+
if changex > 1 or changey > 1:
14+
change = changex if changex > changey else changey
15+
print change
16+
print int(reslution[0] / change), int(reslution[1] / change)
17+
img.resize((int(x / change), int(y / change))).save('result.jpg')
18+
19+
if __name__ == '__main__':
20+
change_resolution('pictest.jpg', (1136, 640))

DIYgod/0005/pictest.jpg

784 KB
Loading

DIYgod/0005/result.jpg

39.7 KB
Loading

0 commit comments

Comments
 (0)