"""HEIC/HEIF thumbnailer for the freedesktop (GNOME/GTK) thumbnail system. Decodes a HEIC/HEIF file's SDR base image with pillow-heif (which bundles a modern libheif) and writes a PNG thumbnail. Used on Linux systems whose *system* libheif is too old to thumbnail iPhone HDR HEICs; installed under /usr/local by scripts/install_heic_thumbnailer.sh so it is reachable inside GNOME's bwrap thumbnailer sandbox (which binds /usr but not $HOME). Invoked by the thumbnail system as: ... -s SIZE INPUT OUTPUT """ import sys def main(argv): args = argv[1:] size, rest = 256, [] i = 0 while i < len(args): if args[i] == "-s": size = int(args[i + 1]); i += 2 else: rest.append(args[i]); i += 1 if len(rest) < 2: sys.stderr.write("usage: heic_thumbnailer.py -s SIZE INPUT OUTPUT\n") return 2 inp, outp = rest[0], rest[1] import pillow_heif pillow_heif.register_heif_opener() from PIL import Image im = Image.open(inp) im.load() im = im.convert("RGB") im.thumbnail((size, size), Image.LANCZOS) im.save(outp, "PNG") return 0 if __name__ == "__main__": sys.exit(main(sys.argv))