Created
March 15, 2018 17:23
-
-
Save galenguyer/db2ef8bdf80935d532da26f1af3bbed9 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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