bensimmo

Representing Data with Images and Sound 2.7

Jan 21st, 2021
530
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. from PIL import Image
  2.  
  3. original = Image.open("puppy.bmp")
  4.  
  5. original_width, original_height = original.size
  6. rotated_width, rotated_height = original_height, original_width # i.e. swap them over
  7.  
  8. rotated_clock = Image.new("RGB", (rotated_width, rotated_height))
  9. rotated_aclock = Image.new("RGB", (rotated_width, rotated_height))
  10. rotated_full = Image.new("RGB", (original_width, original_height))
  11.  
  12. for y_pixel in range(original_height):
  13.     for x_pixel in range(original_width):
  14.         pixel = original.getpixel( (x_pixel, y_pixel) )
  15.         rotated_clock.putpixel((rotated_width - 1 - y_pixel, x_pixel), pixel)
  16.         rotated_aclock.putpixel((y_pixel, rotated_height - 1 - x_pixel), pixel)
  17.         rotated_full.putpixel((original_width - 1 - x_pixel, original_height - 1 - y_pixel), pixel)
  18.  
  19. rotated_clock.save('90rotated_puppy.jpg', 'JPEG')
  20. rotated_aclock.save('a90rotated_puppy.jpg', 'JPEG')
  21. rotated_full.save('fullrotated_puppy.jpg', 'JPEG')
  22.  
  23. rotated_clock.show()
  24. rotated_aclock.show()
  25. rotated_full.show()
RAW Paste Data