python study image mirror 2021-03-31 0 Comments Word Count: 117(words) Read Count: 1(minutes) 安装PIL 1pip install Pillow 单个图片 1234from PIL import Image,ImageOpsimage = Image.open('input.png')image_mirror = ImageOps.mirror(image)image_mirror.save('output.png') 批量 123456789101112131415161718192021import osfrom PIL import Image, ImageOps# 转换一个文件夹def mirrorimage(): outputpath = "/tmp/output" inputpath = "/tmp/input" # 循环文件夹 for image_path in os.listdir(inputpath): # 拼接完整路径 full_path = os.path.join(inputpath, image_path) image = Image.open(os.path.join(inputpath, full_path)) image_mirror = ImageOps.mirror(image) # 拼接输出路径 full_output_path = os.path.join(outputpath, 'mirror_'+image_path) image_mirror.save(full_output_path)if __name__ == '__main__': mirrorimage()