Skip to content

Commit 3372ba9

Browse files
authored
Create main.py
1 parent 4405dad commit 3372ba9

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

step0-Python-Script/imgDeal/main.py

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import os
2+
from PIL import Image
3+
4+
5+
input_file = "./222.jpg"
6+
output_file = "./output.jpg"
7+
8+
im = Image.open(input_file)
9+
size = os.path.getsize(input_file) / 1024
10+
w, h = im.size
11+
12+
# 压缩图片
13+
while size > 100:
14+
w, h = round(w * 0.9), round(h * 0.9)
15+
im = im.resize((w, h), Image.ANTIALIAS)
16+
im.save(output_file)
17+
size = os.path.getsize(output_file) / 1024
18+
19+
# 修改分辨率
20+
im.save(output_file, dpi=(400, 720))

0 commit comments

Comments
 (0)