#!/usr/bin/env python from PIL import Image import sys, random image_file = './test.bmp' zoom = 10 if len(sys.argv) != 3: print "usage: {} ".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("\n\t\n\t\t{}\n\t\t\n\t\n\t\n".format(image_file, zoom)) html_pixels = [ "\t\t
\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\n\n") output.close()