I would like to save a Ruby program coloured terminal output into a png file, output doesn't fit into the screen height, so it is scrollable. Is it possible to save the whole or part of the scrollable terminal window area (not only the visible part of course, but scrolling a bit upwards) into a png file?
You don't have to use a real screen of limited size. Create a virtual screen of the size needed to show all your output at once, then dump that screen or terminal. For example:
$ Xvfb :1 -screen 0 100x4000x24 -noreset & $ xterm -geometry 10x200 -display :1 -e \ sh -c 'echo $WINDOWID >/tmp/id;ls -l /etc;sleep 99' & $ DISPLAY=:1 convert x:$(cat /tmp/id) /tmp/out.png $ identify /tmp/out.png /tmp/out.png PNG 79x2604 ...
This creates a 100 by 4000 pixel screen, with an
xterm 200 lines high.
WINDOWID variable is exported by
xterm, and can be given to ImageMagick's
convert program to copy the image to a png file. The
identify command shows that the whole
xterm contents were captured, which would not be the case on my real screen of only 1080 pixels.
I've been using asciienma.org (previously ascii.io) to create recorded sessions for tutorials that I need to embed/share of actions in a terminal. The recordings can be saved and downloaded into a .cast format which you can then convert to a .gif format.
To convert the .cast files to .gif I use this project - asciicast2gif. The results speak for themselves: