Webdriver Torso

June 2014

 

import cStringIO as StringIO
import random

from PIL import Image, ImageDraw, ImageEnhance


def webdriver_torso(size, name="aqua.flv", slide=None):
    # render test image

    im = Image.new("RGB", size, "white")

    d = ImageDraw.Draw(im)

    # boxes
    for color in "blue", "red":
        x0 = random.randint(1, size[0]-1)
        y0 = random.randint(1, size[1]-1)
        x1 = random.randint(1, size[0]-1)
        y1 = random.randint(1, size[1]-1)
        d.rectangle((x0, y0, x1, y1), fill=color)

    # title
    if slide is None:
        slide = random.randint(0, 10)
    d.text((10, size[1]-30), "%s - Slide %04d" % (name, slide), "black")

    return im


def fuzz(im, quality=480):
    # simulate video compression

    # introduce compression artifacts
    tmp = StringIO.StringIO()
    im.save(tmp, "JPEG", quality=70)
    tmp.seek(0)  # rewind
    im = Image.open(tmp)

    # fuzz the result slightly
    im = ImageEnhance.Sharpness(im).enhance(0.5)

    if quality == 240:
        # simulate 240p
        im = im.resize((426, 240), Image.ANTIALIAS)

    # zoom up to player size
    return im.resize((854, 480), Image.BICUBIC)


im = fuzz(webdriver_torso((640, 360)), 240)

im.show()

A Django site. rendered by a django application. hosted by webfaction.