Advertisement
kaly1

Rotate image 180 degrees

Jun 20th, 2019
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.45 KB | None | 0 0
  1. from PIL import Image
  2.  
  3. original = Image.open("puppy.bmp")
  4. ori_width, ori_height = original.size
  5. rot_width, rot_height = ori_width, ori_height
  6.  
  7. rotated = Image.new("RGB" , (rot_width,rot_height))
  8.  
  9.  
  10. for y in range(ori_height):
  11. for x in range(ori_width):
  12. pixel = original.getpixel((x,y))
  13. rotated.putpixel((rot_width - x - 1, rot_height - y - 1), pixel)
  14.  
  15.  
  16.  
  17. rotated.save('rotated_puppy_2.jpg','JPEG')
  18. rotated.show() #only on Mu
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement