I recently wrote some Python code in my lunch hour at work which assigns a different colour value to the numbers between 0 and 9. These colours produced this simple visulisation of Pi.
A Picture is Worth 1000 Words
OK, so it was 3AM and I had this unrelenting urge to create something. I’d recently been doing some work on a simple script that converted an image into a coloured HTML render, using text instead of pixels. Not a new idea, but still quite a fun one. Taking the existing code I had already written, I modified my script. Now, instead of exporting to HTML, it exported the same data to an image format.
Rather than talking about the specifics of how I did it, I figured I’d just release the code as quite a few people had expressed an interest in using the script for themselves, so here you go, guys, enjoy. You’ll need Python26 and the Python Image Library installed. Invoke the script with `—help’ and it’ll display a handy usage string. If you do use it for anything that you want to share, I would love to see the kind of things you guys come up with.
I figure I should kick things off with THIS. It’s a super big image (13320x20000 weighing in at 70MB) of Johnny Cash stood outside of Folsom Prison. All of the characters that comprise the image are lyrics from his songs. Let me know what you guys think. :)
My super talented friend Michelle recently released her latest Web creation: www.pioneerproject.net. She’s worked frivolously on this project; from coding to capture, from design to DHTML, and from prose to personalisation, she’s done a consistently fantastic job, and I’m sure you’ll agree. So go check it out!
Ubuntu Cola on Sale at University!
As I walked out of my Network Security lecture at University today, I checked my phone to see the following message from my friend, that read:
"I just bought Ubuntu cola from the canteen. Possibly the geekiest drink ever. Tasty though."
I hurried down to the canteen and bought myself the bottle of Fairtrade Ubuntu cola seen below:
I’m going back to University on Monday to pick up some Ubuntu cola for the guys at work! Now all I’m waiting for is my Ubuntu hoody to arrive and I’ll be the coolest kid on campus.
Compressing Superfluous Data in my HTML Art
I mentioned in an earlier blog post concerning the Image to HTML compiler I had built, that the compiler was wildly inefficient, and I had planned various ways of truncating the superfluous code to improve browser rendering time. Well, I just wanted to give away some clues as to how I’m approaching this. 8)
Below is a composite of Sia Furler; the left image is the original and the right is the source image, juxtaposed with seemingly sporadic streaks of green. The green pixel chains are the result of a simplistic linear scan algorithm I scribbled onto a post-it note. Essentially, pixels are compared to their rightmost neighbour. This comparison is measuring the ordinary distance between these pixels in terms of their respective colour values using the Euclidean Distance technique. The result is a contiguous chain of pixels who all share the same colour value.
Think of the green sections as areas of maximum compression without any notable loss to the quality of the image. I’m sure this information alone lends itself to the inquisitive as to just how I’m going to save so much space!
Any way, this is the most rudimentary of the compression techniques I’ve planned to implement, and I’ve got a much more interesting optimisation technique to discuss and share at some point. If you like maths, data, more maths, and some crafty C coding, you may enjoy it.
What I will reveal is that most of the complicated maths and per-pixel processing is being performed by an external C module I’ve built. This module interfaces with my Python scripts and the Python Image Library for super fast image interrogation.
I’m a busy guy, and I don’t have time to work on this continuously. As it stands, it’s had about 3 hours of my time. I’m hoping to finish it in under 10 hours. Thanks to Python, that’s probably possible. We’ll see…
HTML ASCII art using Python (Part 1)
So I decided to sit down and write a simple script to generate a xHTML version of a supplied source image. You pass the script a text file pointer, and that text file will be used as the text for your image. The example below shows a disgustingly fuzzy image of my favourite artist (Sia Furler), and a close-up look at the individual character styling respectively:
While the results from this are promising, the HTML output size is very big, and the image compression on the example images has ruined their look. I’m not hosting the raw HTML code for the image used in this example because it weighs in at over 1MB, and that’s because I’ve not employed any creative forms of compression…yet ;).
My revision of the current version of this script should see a few new and COOL features, such as a built-in compression algorithm that will dramatically reduce the size of the xHTML output (hopefully up-to 33%).
I don’t want to give too much away too soon, but suffice it to say, there are at least 5 different compression techniques I can think of that are worth implementing. Some of you mark-up geeks may be interested to see the implementation specifics, and I’ll be sure to publish them when it’s finished so you can vilify my attempts at creative HTML coding. Either way, reading about a HTML optimiser written in Python is rather cool, right? 8)
I’ll release the code as soon as it’s at a stage where I think someone somewhere could learn something from it. It’s so simple at the moment, it hurts.
Comments are encouraged, so please feel free to comment! Thanks!
A friend linked me to this video of a scientist called Clifford Stoll talking at the TED conference. The energy conveyed by this guy is brilliant. If you get time, sit and watch the whole thing. This guy has an agile mind unlike anyone else I’ve seen both online and in the real world. Fabulous.