Deprecated: Return type of I::current() should either be compatible with Iterator::current(): mixed, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /home/public/kirby/toolkit/lib/i.php on line 62

Deprecated: Return type of I::next() should either be compatible with Iterator::next(): void, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /home/public/kirby/toolkit/lib/i.php on line 91

Deprecated: Return type of I::key() should either be compatible with Iterator::key(): mixed, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /home/public/kirby/toolkit/lib/i.php on line 71

Deprecated: Return type of I::valid() should either be compatible with Iterator::valid(): bool, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /home/public/kirby/toolkit/lib/i.php on line 101

Deprecated: Return type of I::rewind() should either be compatible with Iterator::rewind(): void, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /home/public/kirby/toolkit/lib/i.php on line 53

Deprecated: Return type of Collection::count() should either be compatible with Countable::count(): int, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /home/public/kirby/toolkit/lib/collection.php on line 80

Deprecated: parse_str(): Passing null to parameter #1 ($string) of type string is deprecated in /home/public/kirby/toolkit/lib/url.php on line 135
One Tap Less | Fixing the status bar of iPhone screenshots

Fixing the status bar of iPhone screenshots


Deprecated: trim(): Passing null to parameter #1 ($string) of type string is deprecated in /home/public/kirby/toolkit/lib/str.php on line 506

Deprecated: trim(): Passing null to parameter #1 ($string) of type string is deprecated in /home/public/kirby/toolkit/lib/str.php on line 506

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 = Image.new('RGB',(640,30))
while i < 640:
    gradient.paste(cropbar,(i, 0))
    i = i+10
screenshot.paste(gradient,bar)

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

statusbar = Image.open(folder + barfiles[(width, textcolor)])

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

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: