Guest User

Untitled

a guest
Mar 24th, 2018
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.90 KB | None | 0 0
  1. #!/usr/bin/env python
  2. from PIL import Image
  3. import sys, random
  4.  
  5. image_file = './test.bmp'
  6. zoom = 10
  7.  
  8. if len(sys.argv) != 3:
  9. print "usage: {} <image_file> <zoom>".format(sys.argv[0])
  10. exit(1)
  11. else:
  12. image_file = sys.argv[1]
  13. zoom = int(sys.argv[2])
  14.  
  15. image = Image.open(image_file)
  16. width, height = image.size
  17. image_data = list(image.getdata())
  18.  
  19. output = open('./index.html', 'w')
  20. output.write("<html>\n\t<head>\n\t\t<title>{}</title>\n\t\t<style>\n\t\tbody{{line-height:{}px;}}\n\t\t</style>\n\t</head>\n\t<body>\n".format(image_file, zoom))
  21. html_pixels = [ "\t\t<div style=\"background-color:{0};width:{1}px;height:{1}px;position:absolute;top:{2}px;left:{3}px;\"></div>\n".format('#%02x%02x%02x' % image_data[j + i*width], zoom, i*zoom, j*zoom) for i in range(height) for j in range(width) ]
  22. random.shuffle(html_pixels)
  23. [ output.write(line) for line in html_pixels ]
  24. output.write("\t</body>\n</html>\n")
  25. output.close()
Add Comment
Please, Sign In to add comment