Posted on 2013/09/25 by

Text to Image

With the help of a friend I wrote a program in C# that converts text files into images. I’m not a programmer so please forgive me if I haven’t got the lingo quite right. The code was compiled in Unity and the output was converted from a targa file to a PNG in Gimp (so that I could post it here). Below is a description of the process, including some of the things that occurred to me as I reflected on what I had done. Included in the description is the actual code, and an image of the code used to produce that image.

This is an image of the text you’re about to read:

image_from_text

HexASCII: On Learning to Code

You want to write a program that transforms digital text into image. It’s a problem of translation, of re-visualization. You ask a friend for help. He provides you with a map.

This is the map:

1. open txt file
2. open file that I create
(use tga file format, header + raw data, can use gimp to convert)
3. write tga header to file I created
4. for every char in txt file write that char after the header
5. close files

On a raft of language, pulled by strange currents, you encounter swarms of code, slippery as fish, blooming on the surface of a sea of images and text. The problem is somewhere below you, an oily shadow. You don’t even know what you’re hunting for, not really, and it’s easy to lose your bearings when the whole world seems to shift under your weight. It’s a matter of focus: a tuning of the eyeballs, a flickering of the ears. Like radio stations, recognizable sounds fade in and out of static. Each channel, each layer of abstraction, is like a pane of glass, more or less transparent, more or less cloudy, more or less warped. Each time you manage to break through a pane, you experience a heady rush of oxygen, a flush which leaves you giggling and wheeling, as if you’ve just stepped off a merry-go-round. You feel five years old again, triumphant, emboldened…until you run, face first, into another pane of glass.

Half of you is hunting and half of you is simply being swept away, pulled along by the swarm, by your rumbling belly, by the hands of your friend. You’ve been setting fires along the way. You’ll have to come back for those later. You’ve also been building, and breaking, and re-building. Gates and funnels and tiny machines of sapphire, bubblegum, and tar, that fetch and split and tear and mend and engulf whole strings of commas and bytes.

It’s with these little machines, these hooks and lines, that you finally catch your problem, your enigma:

using UnityEngine;
using System.Collections;
using System;
using System.IO;

namespace FileIOApplication
{
class TargaConverter
{
public static void DoIt()
{
{
BinaryWriter bw;
BinaryReader br;
FileInfo info;

//get text file length
info = new FileInfo(“/Users/carolyn/Documents/HUMA888/text_to_image.txt”);
double size = info.Length;
short width = (short)Math.Round(Math.Sqrt(size/3),0);
short height = width;

//create the file
try
{
bw = new BinaryWriter(new FileStream(“/Users/carolyn/Documents/HUMA888/image_from_text.tga”,
FileMode.Create));
}
catch (IOException e)
{
Console.WriteLine(e.Message + “\n Cannot create file.”);
return;
}
//writing into the file
try
{
byte[] buffer = {
(byte)0,
(byte)0,
(byte)2,
(byte)0,
(byte)0,
(byte)0,
(byte)0,
(byte)0,
(byte)0,
(byte)0,
(byte)0,
(byte)0,
(byte)(width & 0x00FF),
(byte)((width & 0xFF00) / 256),
(byte)(height & 0x00FF),
(byte)((height & 0xFF00) / 256),
(byte)24,
(byte)0
} ;
bw.Write(buffer);
}
catch (IOException e)
{
Console.WriteLine(e.Message + “\n Cannot write to file.”);
return;
}
//reading from the file
try
{
br = new BinaryReader(new FileStream(“/Users/carolyn/Documents/HUMA888/text_to_image.txt”,
FileMode.Open));
}
catch (IOException e)
{
Console.WriteLine(e.Message + “\n Cannot open file.”);
return;
}

try
{
while(true)
{
bw.Write(br.ReadByte());
}
}
catch (EndOfStreamException e)
{
Console.WriteLine(e.Message + “\n Reached end of file.”);
return;
}
catch (IOException e)
{
Console.WriteLine(e.Message + “\n Error”);
}
br.Close();
bw.Close();
}
}
}
}

public class TexttoImage : MonoBehaviour {

// Use this for initialization
void Start () {
FileIOApplication.TargaConverter.DoIt();

}

// Update is called once per frame
void Update () {

}
}

recursion
It’s with these that you crystallize its form, pry open its jaws, and peel back its skin. And while you’re eager to plunge your fingers into its slick, silvery body, to pluck out each organ like a green grape, and unravel its veins, you’re also afraid. The interior is bigger than it first appeared. The chambers are multiple, cavernous, and filled with echoes, and you are suddenly aware of just how little you know. What will you create with this shell of an enigma? A house of mirrors? A carpet of noise? A mosaic? What you want is explosives, an open wound, a photograph that makes it all worthwhile. No more plastic, no more smug remarks hanging from the ceiling like chintzy chandeliers, no more hollow words soaked in alcohol and wrapped in leaves of smoke, no more pretentious bullshit overflowing porcelain bowls, no more howling girls and deaf ears (especially that), no more humans, no more objects, only process, only change.

For a moment you place the enigma over your head, like a mask, and try to explain.

All things are in motion. Stasis is an illusion concocted by humans who feel sick to their stomach when they try to imagine otherwise; ideology is the vomit. We are swimming in our own vomit. We think we prefer simple lies to complex truth when in reality, we swap simple truth for complex lies that rattle with contradictions. Of course preference has nothing to do with it; agency and reality are convenient fictions, tools in the hands of the powerful and the influential. Tools to brand us as heroes or criminals, tools to funnel us into our respective institutions, tools to carve “you are free” on the insides of our skulls. What is freedom really? Freedom to crawl out of the mire, freedom to stop saying yes sir, no sir, freedom to play, freedom to work as we will for what we will, freedom to overthrow.

All this with a little program, you say? All this with a simple problem of translation, of re-visualization, of indexical relations? Of course not. This is nothing but a fragment, a small chunk of plaster torn from the wall. But even this is beginning to expose the wire-laced ribs of the rules and devices in which we’ve placed so much of our trust.

What happens when we take a familiar face, and turn it inside out? The point isn’t to see an inverted face, the point is to find out what makes it tick, who made it, and why. The point is to see everything as arbitrary, artificial, constructed. The point is to tear it down and remake it in our own image. Fuck Mount Rushmore, fuck Steve Jobs, fuck Microsoft and its proprietary software. We are a direct threat to all of that, but it’s only when we pick up the tools, only when we turn privilege against itself and peel back the skin, only when we learn to dig our fingernails into the oil-drenched belly of the beast, only then do we feel, in a cold sweat, the flesh, blood, and bone beneath this shining world of circuitry and digits.

Learning to code is no more revolutionary than learning to read and write.

Learning to code is no less revolutionary than learning to read and write.

Print Friendly