当前位置: 代码迷 >> 综合 >> python批量旋转图片
  详细解决方案

python批量旋转图片

热度:22   发布时间:2024-02-09 05:20:59.0

工作中偶尔会用到图像批量选装,找工具有点麻烦,就查了一下python脚本。

双击一下就能完成的任务,为啥非要找工具呢,是吧。

#-*- coding: UTF-8 -*-from PIL import Image
import os# 获得文件夹下所有文件
filePath = './imgs/'
filenames = os.listdir(filePath)# 指定保存的文件夹
outputPath = './imgs_rotate/'# 迭代所有图片
for filename in filenames:# 读取图像im = Image.open(filePath + filename)# 指定逆时针旋转的角度im_rotate = im.transpose(Image.ROTATE_90)# im_rotate = im.transpose(Image.ROTATE_180)# im_rotate = im.transpose(Image.ROTATE_270)# 保存图像im_rotate.save(outputPath + filename)

 

 

参考:【python图像处理】图像的缩放、旋转与翻转

  相关解决方案