#!/usr/bin/env python3 # -*- coding: utf-8 -*- import os, random, base64 dir ='.' extensions = [ '.ras', '.xwd', '.bmp', '.jpe', '.jpg', '.jpeg', '.xpm', '.ief', '.pbm', '.tif', '.gif', '.ppm', '.xbm', '.tiff', '.rgb', '.pgm', '.png', '.pnm'] imgs = list() for (dirpath, dirnames, filenames) in os.walk(dir): imgs += [os.path.join(dirpath, file) for file in filenames if file.endswith(tuple(extensions))] random_img = random.choice(imgs) with open(random_img, 'rb') as img_file: random_img_string = base64.b64encode(img_file.read()) random_img_string = random_img_string.decode('utf-8') random_img_string = 'data:image;base64,' + random_img_string print('Content-type: text/html') print('') print('''

IMAGE ROULETTE

{1}

'''.format(random_img_string, random_img))