#!/usr/bin/env python3
import sys
from PIL import Image

args = sys.argv[1:]
# sips -g pixelHeight -g pixelWidth <file>
if "-g" in args:
    path = args[-1]
    im = Image.open(path)
    w, h = im.size
    print(path)
    # print in the order requested
    i = 0
    while i < len(args) - 1:
        if args[i] == "-g" and i + 1 < len(args):
            key = args[i + 1]
            if key == "pixelWidth":
                print(f"  pixelWidth: {w}")
            elif key == "pixelHeight":
                print(f"  pixelHeight: {h}")
            i += 2
        else:
            i += 1
    sys.exit(0)
print("sips shim: unsupported", args, file=sys.stderr)
sys.exit(1)
