Advertisement
Guest User

a tiny file differ (creates a PPM image)

a guest
Jan 29th, 2015
219
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.55 KB | None | 0 0
  1. # a tiny file differ (creates a PPM image)
  2.  
  3. WIDTH = 32
  4. WHITE = "\xff\xff\xff"
  5. RED = "\xff\0\0"
  6. import sys
  7.  
  8. filename1, filename2, imagename = sys.argv[1:4]
  9.  
  10. with open(filename1, "rb") as f:
  11.     d1 = f.read()
  12. with open(filename2, "rb") as f:
  13.     d2 = f.read()
  14.  
  15. assert len(d1) == len(d2)
  16.  
  17. HEIGHT = (len(d1) / WIDTH) + 1
  18.  
  19. pixels = []
  20. for i,j in enumerate(d1):
  21.     pixels.append(WHITE if d1[i] == d2[i] else RED)
  22. #remaining pixels will be black
  23.  
  24.  
  25. with open(imagename, "wb") as f:
  26.     f.write("P6 %i %i 255 " % (WIDTH, HEIGHT))
  27.     f.write("".join(pixels))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement