Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Overlay full strength graphics on statusbar of an iOS screenshot when the device is using wifi.
#!/usr/bin/python
import Image
import base64, zlib
# Jay Parlar convinced me to turn this data structure
# from a dictionary into an object.
class PackedImage(object):
def __init__(self, mode, size, data):
self.mode = mode
self.size = size
self.data = ''.join(data)
def unpack(self):
return Image.fromstring(self.mode,
self.size,
zlib.decompress(base64.b64decode(self.data)))
def cleanbar(screenshot):
'''Clean up the statusbar in an iOS screenshot.
Cover the signal strength, battery, location, and bluetooth
graphics with full strength symbols.'''
# This is for retina displays.
height = 40
# Statusbar image data for an iPhone 4, 4s, 5, 5c, or 5s portrait screenshot.
# The data string is compressed and base64-encoded.
limg = PackedImage('L',
(200, 40),
['eJztlltIFFEYx896v6SSKCaJ2uZDD22UUVtBJBWZaS9BSgnWQy',
'ShvSgk9hLdTMl8ENIVozCSCsTqKUW6qFCiYQaZ2oOrq4iUtKm4',
'OW7MvzOzM7Ozl3bE8RI0v4fzne+cb2f+/z1nzgwhGhoaGhoaGh',
'r/AxF6vZ8jyAjlpwLjdM4ij1kZgenlbSPTmBlpK08PXEXtchqB',
'TBryISedjuhbFjBXE80Xec7KSKyakk1OVSWtugfK+l9zeEbj4a',
'ccoxjg4zZCwobRdf87Ov2Jt1knEZUMXGEqo1bfRyGujtvjxOwR',
'bord02gmJGgEu521slmJvWZOetfltHg/4hd/oPQdl5r3LeLOib',
'WjjKU2SWUm8pHV30aJF6WXUETbauT49HF2gcpuNshGDE3ckuQp',
'2kif4Rdv9qiqTCQVHWQ7hrwoTUMrbd9ji08fGQymjrmPTYFxH/',
'MgeVrYhbPJKjKJGpwjpB/7PZUGD+MEuYEnsmJv+yq7V0/bgMz6',
'PiusffVZATTT92Yr2SAm6XEyqchEQn7aIgkpxUMvSg+y1la0r1',
'PwQeihrcszS1c3n9HxY0pYpF9YVGQiuXhM22TWFuWpNHYQqAqS',
'39urD3rkvYSclmhlF4TMS/WMbumZyFtkcKETFzyUnrS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2P0UShdvuA4V8dPhf8x9JMo3Yb6SEeOZAptG+qFuF3gRbNHYAX',
'AEukgXUAw3+5AXbAKBgFwxUAAElqKPY='])
# Calculate various dimensions based on the size of the screenshot.
width = screenshot.size[0]
lbox = (0, 0, limg.size[0], limg.size[1])
rbox = (width - rimg.size[0], 0, width, rimg.size[1])
# Decide whether the overlay text and graphics should be black or white.
# The pixel at (width-13, 21) is in the button of the battery.
p = screenshot.getpixel((width-13, 21))[:3]
if sum(p) > 3*250:
symbolcolor = 'white'
else:
symbolcolor = 'black'
# Create the masks.
lmask = limg.unpack()
rmask = rimg.unpack()
# Make the overlays.
left = Image.new('RGBA', limg.size, symbolcolor)
left.putalpha(lmask)
right = Image.new('RGBA', rimg.size, symbolcolor)
right.putalpha(rmask)
# Paste the overlays and return.
screenshot.paste(left, lbox, left)
screenshot.paste(right, rbox, right)
return screenshot
# And here we go.
if __name__ == '__main__':
import photos, console
screenshot = photos.pick_image()
console.clear()
cleanbar(screenshot).show()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.