from PIL import Image
import os
def change_photo(new_path, photo_path):
im = Image.open(photo_path)
im_rotate = im.rotate(-180, expand=1)
if os.path.exists(new_dir_path) == False:
os.makedirs(new_dir_path)
im_rotate.save(new_path)
print(photo_path,'======>',new_path)
dir_path = 'C:\\zhangyingyi\\桌面\\pic_rgb\\'
new_dir_path = 'C:\\zhangyingyi\\桌面\\pic_rgb\\new\\'
fileList=os.listdir(dir_path)
n=0
for i in fileList:
change_photo(new_dir_path+fileList[n], dir_path+fileList[n])
n+=1
import os
path='C:\\zhangyingyi\\桌面\\pic_rgb\\'
fileList=os.listdir(path)
n=0
for i in fileList:
oldname=path + fileList[n]
name = fileList[n].split('.')
newname= path + name[0]+'.jpeg'
os.rename(oldname,newname)
print(oldname,'======>',newname)
n+=1