3

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?

  • Workarounds: 1. Change to a smaller font, to show more (or all) of the content in the window; 2. Mark and paste the whole content of the window to a file. This means that you wil lose the colours; 3. Redirect (if possible) the output to a file. This might preserve the colour information, so that it can be rendered (for example by cat file). – sudodus Jul 29 '18 at 18:26
1

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. The 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.

1

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:

ss1

References

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.