[Python] 纯文本查看 复制代码 from PIL import Image
import os
Modify_dimensions_width = input('输入需要修改的宽度:')
Modify_dimensions_width = int(Modify_dimensions_width)
path = r'修改完成\\'
os.makedirs(path, exist_ok=True)
work_path = os.path.abspath(os.path.dirname(__file__))
for a,b,c in os.walk(work_path):
for name in c:
try:
work_path_name = a+'\\'+name
img = Image.open(work_path_name,'r')
width = img.width
heigth = img.height
e = round(heigth*(Modify_dimensions_width/width))
work_img = img.resize((Modify_dimensions_width,e),Image.ANTIALIAS)
work_img.save(path+name,quality=100, optimize=True)
except:
pass
esc = input('回车结束')
为啥只有宽度,高度呢 |