Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/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()
Add Comment
Please, Sign In to add comment