from PIL import Image
import os# 定义函数,旋转图片并保存
def rotate_images(input_dir, output_dir, angle):for filename in os.listdir(input_dir):# 判断文件是否为图片if filename.endswith('.jpg') or filename.endswith('.png'):# 打开图片img = Image.open(os.path.join(input_dir, filename))# 旋转图片,使用expand=True参数来确保旋转后的图像不会被裁剪,若要裁剪图像,可以将此参数设置为False。rotated_img = img.rotate(angle, expand=True)# 保存旋转后的图片rotated_img.save(os.path.join(output_dir, filename))# 输入文件夹路径、输出文件夹路径、旋转角度
input_dir = 'D:\\images'
output_dir = 'D:\\images_out'
angle = 345 # 逆时针旋转度数rotate_images(input_dir, output_dir, angle)
本文来自互联网用户投稿,文章观点仅代表作者本人,不代表本站立场,不承担相关法律责任。如若转载,请注明出处。 如若内容造成侵权/违法违规/事实不符,请点击【内容举报】进行投诉反馈!