- #coding=utf-8
- from PIL import Image
- import random
- def Jpg(dir_line):
- try:
- im=Image.open(dir_line)
- except IOError as er_info:
- print er_info
- exit()
- x=im.size[0]
- y=im.size[1]
- img=im.load()
- c = Image.new("RGB",(x,y))
- for i in range (0,x):
- for j in range (0,y):
- w=x-i-1
- h=y-j-1
- rgb=img[w,j] #镜像翻转
- rgb=img[w,h] #翻转180度
- rgv=img[i,h] #上下翻转
- c.putpixel([i,j],rgb)
- #90度的翻转实现
- ''''' y=im.size[0]
- x=im.size[1]
- img=im.load()
- c = Image.new("RGB",(x,y))
- for i in range (0,x):
- for j in range (0,y):
- w=x-i-1
- h=y-j-1
- rgb=img[j,i]#翻转90度
- c.putpixel([i,j],rgb)'''
- c.show()
- c.save("c.png")
- if __name__=="__main__":
- name="1.jpg"
- Jpg(name)
- 原图:
镜像翻转:
转自:http://blog.csdn.net/reverseboy/article/details/45418305