#!/usr/bin/env python3 # ported to python 3 (and opacity argument added) by samicrusader from PIL import Image import sys, random if len(sys.argv) != 3: print("usage: {} ".format(sys.argv[0])) exit(1) else: image_file = sys.argv[1] output_file = sys.argv[1] + '.html' zoom = int(sys.argv[2]) image = Image.open(image_file) width, height = image.size image_data = list(image.getdata()) output = open(output_file, 'w') output.write("\n\t\n\t\t{}\n\t\t\n\t\n\t\n".format(image_file, zoom)) template = '\t\t
\n' html_pixels = [ template.format('#%02x%02x%02x' % image_data[j + i*width][:3], zoom, i*zoom, j*zoom, image_data[j + i*width][-1]/255) 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()