from PIL import Image
import os
x = 480
y = 640
# 当前照片路径
img_path = 'img'
# 输出照片路径
output_path = 'new_img'
# 修改图片大小
def smaller_img(x, y, path, copy_path):
path = str(path)
old_img = Image.open(path)
img_deal = old_img.resize((x, y), Image.ANTIALIAS)
img_deal = img_deal.convert('RGB')
img_deal.save(f'{copy_path}\{file_name}')
# 遍历文件夹下的文件,并判断是否是JPG文件
for file_name in os.listdir(img_path):
files_path = f'{img_path}\{file_name}'
if 'jpg' in files_path:
smaller_img(x, y, files_path, output_
网友评论