Creating Static

For the first ever blog entry here, I decided to talk about a simple project that has been on my mind for a few months. But first, let me ask this. Do you have a LinkedIn profile? Do you use a neat clean photo of yourself so recruiters and HR know who to expect? I did and if you’re like me, you may wonder if people are making hiring judgments based on your image versus your profile as a whole. And if you’re like me, you may be suspicious of LinkedIn being a goldmine for potential hackers to gather information on you.

So delete your profile, right? Sure…if you don’t have a life. Since I do have a life, deleting my profile isn’t really option. Plus, you don’t want some random stranger to take your name, make a profile, and LinkedIn stalk people with creepy messages. Your reputation is at stake after all. This is where I had the idea to remove the picture of my beautiful face and replace it with an edited version of a stock photo. You know. The very generic image of binary cascading down the screen in Matrix green. Pretty cool and this was fine until a new thought occurred: Do I need to be the owner of any photo posted?

Honestly, I am too lazy to find the answer to this question so I decided to just make a photo. This way, the image is of my own creation, looks cool, and shows off some of my abilities. Plus, it would be more fun to make than looking up legal terms.

First things first. I needed to figure out how to make an image. Naturally, I wanted create the image using a programming language. Python was my poison Then, I worked out in broad terms how to create the image which goes something like this:

  • Create a blank image file.
  • Read in some text.
  • Take a pixel at a time and set its color based on the ASCII values of the current three characters of the text stream.
  • Marvel/cringe at creation.

FUN TECH STUFF!

This the part of the blog where I get a bit more technical for a moment. If you want, you can skip this paragraph. As most people know, computers uses binary (0,1) as the building block of everything it does. A bit is simply a 1 or a 0. A byte is 8 bits put together and typically represent a value. I won’t go into too much binary math but keep in mind that 2 to the power of 8 is 256. Since 0 is the start of binary counting, subtract 1 and we get 255 as the largest number a byte can represent in binary math. The fun thing is that letters like ‘A’ are represented as a byte. Guess what else is represented as a byte? Color values! And pixels each have 3 color values (RGB). So we can take the byte representation of ‘A’ and use that as one of the RGB color values in a pixel! Simple programming!

I fired up my computer and jumped on a Linux VM. Since I have never done image manipulation in Python before, I had to look up what I would need to make this happen. There is a python module called PIL that would handle everything I needed. To use this, I had to download dependencies and install through pip. Of course, the add-on to install is called Pillow and not PIL because why make life easy?

Once all of that was done, it was time to break out trusty, old VIM and incrementally build the program. First, I made sure I knew how to create an image file. Then, I ran tests to open a file, copy its contents to a variable, access individual characters in the variable, and get the ascii value of said character. Next, create my double loops to get each pixel and set its color based on the current character and the following two characters in the variable. Finally, once all the syntax errors were conquered, marvel my creation.

It worked…but it was ugly. Sure, it’s supposed to look like static but it was ugly static. Not only that, I was using a text file with maybe 15 words in it. Clearly time to do a little cosmetic work. I went online and browsed to a journalistic website. Got the article url and ran cURL to download the source code as a text file. Now I have plenty of characters to create an image! I plugged in the new file and got a new image. Still a little ugly and it looked dark and depressing. I tried adding a random number to all of the color values to brighten the image which worked but it still looked off to me. It looked a bit clunky. I thought of ways to try to make the color values more random while using the modulus operator to make sure the number result does not go over 255.

After more playing and tweaking, I felt that I finally had a nice program to generate static images. I saved one of the images, hopped on to LinkedIn, and slapped the image on as my profile pic! I’m pretty happy with the resulting image and I dare say it looks kinda badass.

Where to from here? I think it would be nice to pass in variables like the image size, which file to read from and what to save the image as. Things I can add later. For now, one more roadblock for potential hackers to link me to my place of work. No social engineering for this guy! (I hope)

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s