from PIL import Image
import os
# 图片旋转
# new_path转后后图片完整路径,photo_path原始完整路径(带文件名)
def change_photo(new_path, photo_path):
im = Image.open(photo_path)
im_rotate = im.rotate(-90, expand=1) # expand=1 表示原图直接旋转
im_rotate.save(new_path)
path = 'C:\\Users\\aaa\\Desktop\\pic2\\'
filepaths=os.listdir(path)
for i in filepaths:
imgs=os.listdir(path+i)
for j in imgs:
p=path+'c_'+i
if not os.path.exists(p):
os.makedirs(p)
change_photo(path+'new_'+i+'/new_'+j, path+i+'/'+j)