So now I’ve finished my digital Holga project, one of the things I wanted to do was to get a bit creative with it – so here’s my first attempt at an ASCII art generating camera.
This uses the ASCII art script written by Steven Kay, please visit his blog to find out more – I’ve modified the original script to use the python picamera library – this helps speed up the image resize. There’s also a timestamp added to the text file which uses the same script I wrote about in my previous Holga post.
If you just want to run Steven Kay’s script you’ll need the python imaging tools – install with
sudo apt-get install python-imaging
Here’s my modified script:
''' ASCII Art maker Creates an ascii art image from an arbitrary image Created on 7 Sep 2009 @author: Steven Kay ''' import time import picamera from PIL import Image import random from bisect import bisect # greyscale.. the following strings represent # 7 tonal ranges, from lighter to darker. # for a given pixel tonal level, choose a character # at random from that range. greyscale = [ " ", " ", ".,-", "_ivc=!/|\\~", "gjez2]/(YL)t[+T7Vf", "mdK4ZGbNDXY5P*Q", "W8KMA", "#%$" ] # using the bisect class to put luminosity values # in various ranges. # these are the luminosity cut-off points for each # of the 7 tonal levels. At the moment, these are 7 bands # of even width, but they could be changed to boost # contrast or change gamma, for example. zonebounds=[36,72,108,144,180,216,252] #take photo with picamera.PiCamera() as camera: camera.capture('image.jpg'); # open image and resize # experiment with aspect ratios according to font im=Image.open(r"image.jpg") im=im.resize((160, 75),Image.BILINEAR) im=im.convert("L") # convert to mono # now, work our way over the pixels # build up str str="" for y in range(0,im.size): for x in range(0,im.size): lum=255-im.getpixel((x,y)) row=bisect(zonebounds,lum) possibles=greyscale[row] str=str+possibles[random.randint(0,len(possibles)-1)] str=str+"\n" print str date_string = time.strftime("%Y-%m-%d-%H:%M:%S") text_file = open('image' + date_string + '.txt', "w") text_file.write(str) text_file.close()
There are lots of settings to tweak – the image above was generated by the script – and bear in mind this is designed to be viewed with black text on a white background. Perhaps I’ll see if I can dig out an old dot matrix printer from somewhere.
For a blog of ‘photos’ updated whenever I take them and am in range of WiFi check out:
This emails the ASCII art in HTML format to blogger whenever I take a photo (and the Pi Holga is in range of the internet).