Fixing the status bar of iPhone screenshots

There was a commotion this week to clean up iPhone screenshots, I hope Viticci’s OCD is limited to that. I only had the time to play with script today and you can check the efforts by Dr. Drang in his blog. It works great with app screenshots, but why stop there? I want my home screen pictures to look awesome as well.

Danilo Torrisi (you’ll hear more about him soon, I promise) built a script that grabs the color of the first pixel of every row and fills the entire row afterwards. Take a look!

I use a linear gradient as home screen background, meaning that whenever I use Dr. Drang’s script I get the following outcome:

This leads to 2 issues:

  1. Grabbing the color of the first pixel on the upper left corner won’t sustain your gradient.
  2. It will take the scalp out of your top row badges.

So I included a few lines of code to Dr. Drang’s script, but since I have no experience with PIL at all, I’m using a while loop and I kinda feel sad for it.

My script is based on finding a safe spot to crop the screenshot, a tiny 10x30 slice and create a new image with it, repeated side by side 64 times. If you’re already lost in numbers, it creates a 640x30 image the script will paste on the top of your screenshot and, afterwards, paste the text according to the if statement.

from __future__ import division
import Image
import sys, os
import photos, clipboard, console

# Dictionary of file names keyed to width and color.
barfiles = {(640, "black"): "640b.png",
            (640, "white"): "640w.png",
            (1136, "black"): "1136b.png",
            (1136, "white"): "1136w.png"}

# Where the status bar files are.
folder = os.environ['HOME'] + '/Documents/'

# Open the screenshot and fill its statusbar with the background color.
screenshot = photos.pick_image()
width = screenshot.size[0]
bar = (0,0)
barcolor = screenshot.getpixel((0, 0))

cropbar = screenshot.crop((220,0,230,30))
i = 0
gradient ='RGB',(640,30))
while i < 640:
    gradient.paste(cropbar,(i, 0))
    i = i+10

# Decide whether the overlay text and graphics should be black or white.
if sum(barcolor[:3])/3 > 192:
  textcolor = "black"
  textcolor = "white"

statusbar = + barfiles[(width, textcolor)])

# Paste the overlay and save.
screenshot.paste(statusbar, bar, statusbar)

I could cut 10px from the bottom of Dr. Drang’s images to smooth this code, but I got a badass flu this weekend and I don’t even know how I’m writing this piece. Since I’m not filling an area with a color, I’m pasting an image instead, I modified the bar variable into a 2-tuple, allowing me to use it with the 640x30 gradient and the 640x40 text. Notice how I also removed the screenshot.paste(barcolor, bar) line, since it is useless now. The barcolor variable is still used to define what text will be pasted, so I left it there.

I cropped the original screenshot in an area of the status bar I consider safe to crop, I found out that the place between my signal and connection information and the time are often clean, so I crop there. I create a new image and I set a while loop to paste the crop on it, side by side, until its width is 640 px. After that I just paste the outcome in the top of our original screenshot and voilá. This is the outcome: