当前位置: 移动技术网 > IT编程>脚本编程>Python > python实现旋转和水平翻转的方法

python实现旋转和水平翻转的方法

2018年11月05日  | 移动技术网IT编程  | 我要评论

重庆农村商业银行笔试,貂蝉古尸容貌复原图,新河吧

如下所示:

# coding=utf-8
import glob
import os

from pil import image


def rotate_270(imgae):
"""
将图片旋转270度
"""
# 读取图像
im = image.open(imgae)
# im.show()
# 指定逆时针旋转的角度
im_rotate = im.rotate(270)
# im_rotate.show()
return im_rotate


def flip_horizontal(image):
"""
将图片水平翻转
"""
im = image.open(image)
# im.show()
im_fh = im.transpose(image.flip_left_right)
# im_fh.show()
return im_fh


def createfile(path):
isexists = os.path.exists(path)
# 判断结果
if not isexists:
# 如果不存在则创建目录
# 创建目录操作函数
os.makedirs(path)
return true
else:
# 如果目录存在则不创建,并提示目录已存在
print('%s 目录已存在' % path)
return false


def main():
path = 'd:/videophotos/hongshi/'
createfile('d:/videophotos/hongshi_rotate')
createfile('d:/videophotos/hongshi_flip_horizontal')

dirs = os.listdir(path)
for dir in dirs:
# print(dir)
createfile('d:/videophotos/hongshi_rotate/' + dir)
createfile('d:/videophotos/hongshi_flip_horizontal/' + dir)

images = glob.glob(path + dir + r"\*.jpg")
for image in images:
image_name = image[image.find("\\"):]
print(image_name)
rotate_270(image).save('d:/videophotos/hongshi_rotate/' + dir +
image_name)
flip_horizontal(image).save(
'd:/videophotos/hongshi_flip_horizontal/' + dir + image_name)


if __name__ == '__main__':
main()

以上这篇python实现旋转和水平翻转的方法就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持移动技术网。

如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复

相关文章:

验证码:
移动技术网