2024-08-24

Terminal Images Protocols

Terminal with an image

Some terminals are capable of displaying images. It is rarely needed, but sometimes it can be useful.

iTerm2 introduced an Inline Images Protocol, that is now supported by WezTerm as well. A running program can output a Base-64 encoded image to the terminal (wrapped in special control sequences), and the terminal will display this image.

<ESC>]1337;File=width=60;height=auto:<base-64 encoded image>^G

Kitty terminal came up with Terminal Graphics Protocol, which has more capabilities. For example, you can specify the position of the image on the screen, display animations, and remove previously displayed images.

<ESC>_Ga=T,f=100,t=d,m=1;<base-64 encoded image><ECS>\

For Go, I recommend the rasterm library, which implements both protocols.