Skip to content

Instantly share code, notes, and snippets.

@galenguyer
Created March 15, 2018 17:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save galenguyer/db2ef8bdf80935d532da26f1af3bbed9 to your computer and use it in GitHub Desktop.
Save galenguyer/db2ef8bdf80935d532da26f1af3bbed9 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
from PIL import Image
import sys, random
image_file = './test.bmp'
zoom = 10
if len(sys.argv) != 3:
print "usage: {} <image_file> <zoom>".format(sys.argv[0])
exit(1)
else:
image_file = sys.argv[1]
zoom = int(sys.argv[2])
image = Image.open(image_file)
width, height = image.size
image_data = list(image.getdata())
output = open('./index.html', 'w')
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))
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) ]
random.shuffle(html_pixels)
[ output.write(line) for line in html_pixels ]
output.write("\t</body>\n</html>\n")
output.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment