User Error! Please replace user and press any key to continue.

Textify: Asciifying web proxy

Written by Eric Schwimmer

What was that? You are looking for a proxy that will convert any page into ascii art? Then you have come to the right place, my friend! All you will need to do is install phantomjs, fapws, and the PIL and selenium Python modules, and then run this script as a daemon:


import fapws._evwsgi as evwsgi
from fapws import base
from fapws.contrib import zip, log
from selenium import webdriver
import random, sys
from PIL import Image

txtPx = "BG0O$&#@?7>!:-;.  "

def start():
    evwsgi.start('', '8080')


    def textfin(environ, start_response):
        start_response('200 OK', [('Content-Type','text/html')])

        targetUrl = environ['fapws.uri'][1:]
        if not targetUrl:
            return [ 'TextIt!  Usage: %s://%s/<full url to textify>' % (

        outputFile = '/tmp/%032x' % random.randrange(16**32)
        driver = webdriver.PhantomJS()
        driver.set_window_size(1120, 550)

        maxLen = 700
        img =
        width, height = img.size
        rate = maxLen / float(width)
        width = int(rate * width)
        height = int(rate * height)
        img = img.resize((width, height))
        imgData = img.load()

        out = ""
        for h in xrange(height):
            for w in xrange(width):
                px = imgData[w, h]
                    if len(px) > 3:
                        out += txtPx[
                              int(max(sum(px[:2]) / 3.0, 256.0 - px[3]) / 16)]
                        out += txtPx[int(sum(px) / 48.0)]
                    print int(max(sum(px[:2]) / 3.0, 256.0 - px[3])) / 16
            out += "\n"

        return [ '''<html>
              <meta http-equiv="content-type" 
                content="text/html; charset=utf-8" />
              <link href='' 
                rel='stylesheet' type='text/css'>
              <style type="text/css" media="all">
                body {
                  margin: 0 0 0 0;
                pre {
                  font-family: 'Cousine';
                  line-height: 0.182vw;
                  font-size: 0.235vw;
                  font-weight: 900;
            </html>''' % out ]

    evwsgi.wsgi_cb(('/', textfin))


if __name__ == '__main__':

You'll probably want to put it behind varnish or some other sort of caching reverse proxy, because it can be pretty slow on larger pages.

comments powered by Disqus