#!/usr/bin/env python3 # TODO: Consider removing when Kitty Graphics Addon is shipped. """ Minimal Kitty Graphics Protocol image sender. Based on: https://sw.kovidgoyal.net/kitty/graphics-protocol/#a-minimal-example Usage: ./send-png black-1x1.png ./send-png rgb-3x1.png """ import sys from base64 import standard_b64encode def serialize_image(path): with open(path, 'rb') as f: data = f.read() return standard_b64encode(data).decode('ascii') def write_chunked(data): # a=T means transmit and display # f=100 means PNG format # For small images, single chunk (no chunking needed) sys.stdout.write(f'\x1b_Ga=T,f=100;{data}\x1b\\') sys.stdout.flush() if __name__ == '__main__': if len(sys.argv) < 2: print("Usage: ./send-png ", file=sys.stderr) sys.exit(1) img_data = serialize_image(sys.argv[1]) write_chunked(img_data) print() # newline after the sequence