#!/usr/bin/python # -*- coding: utf-8 -*- # pyimg2html v0.0.0.1 # code by shellex import Image import sys import random adjust = 0.7 char_set = 'A' font_size = 3 char_set_len = len(char_set) def make_html_tag(rgb): color = '' for e in rgb: c = hex(e).replace('0x', '') color += '0'+c if len(c) == 1 else c ch = char_set[int(random.random()*char_set_len)] tag = '%s' % (font_size,color, ch) return tag def make_matrix(infile, outfile, new_w, new_h, zoom): im = Image.open(infile) im = im.convert('RGB') w, h = im.size im = im.resize((w, int(h*adjust))) w, h = im.size if new_w!=-1 and new_h!=-1: im = im.resize((new_w, new_h)) w, h = im.size if zoom != -1: im = im.resize((int(w*zoom), int(h*zoom))) w, h = im.size pix = im.load() f = open(outfile, 'w') f.write('
'%font_size)
for y in range(0, h):
for x in range(0, w):
f.write(make_html_tag(pix[x, y]))
f.write('
\n')
f.write('