"""Keep the app viewport after checking two captures made at least 500 ms apart.

Only the iOS system status bar (top 54 points) is excluded; app pixels are unchanged.
Usage: python stable-mobile-capture.py first.png second.png output.png
"""
import sys
from PIL import Image, ImageChops

first, second, output = sys.argv[1:]
images = [Image.open(source).convert('RGB') for source in [first, second]]
assert images[0].size == images[1].size == (402, 874)
viewports = [image.crop((0, 54, 402, 874)) for image in images]
assert ImageChops.difference(*viewports).getbbox() is None, 'App viewport is still changing'
viewports[1].save(output)
