python对图片进行水平 垂直翻转及按一定角度旋转
作者:互联网
python对图片进行翻转
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)
out1 = im.transpose(Image.FLIP_LEFT_RIGHT) #水平翻转
out2 = im.transpose(Image.FLIP_TOP_BOTTOM) #垂直翻转
out3 = im.rotate(45) #45°顺时针翻转
newname = r"C:\Users\wy\Desktop\kd_1" + '\\' + filename + "(1).jpg"
out.save(newname)
标签:python,currentPath,Image,旋转,im,filename,os,翻转 来源: https://blog.csdn.net/qq_17498785/article/details/104866133