from PIL import Image
import os
import os.path
rootdir = r'C:\Users\wy\Desktop\kd' #讀取文件夾位置
for parent, dirnames, filenames in os.walk(rootdir):
for filename in filenames:
print('parentis :' + parent)
print('filenameis :' + filename)
currentPath = os.path.join(parent, filename)
print('thefulll name of the file is :' + currentPath)
im = Image.open(currentPath)
out = im.transpose(Image.FLIP_LEFT_RIGHT) #水平翻轉
# out = im.transpose(Image.FLIP_TOP_BOTTOM) #垂直翻轉
# out = im.rotate(45) #45°順時針翻轉
newname = r"C:\Users\wy\Desktop\kd_1" + '\\' + filename + "(1).jpg"
out.save(newname)