I have written something similar before here: https://github.com/FreeFull/termimage . My program though is just a simple toy, since it doesn't even consider the size on the terminal, and doesn't play animated gifs. On the other hand, the source code for my image viewer almost completely fits on my screen (if you ignore its use of libraries for terminal handling and image reading).