10

I need to programmatically run some unix commands and get the output in a image file, the format could be png or jpeg (jpg).

The commands are run in an AIX (IBM *nix) machine. I don't have permission to install new packages, however I think there a way to do this using a pipeline and redirections with the default packages from the Operating System.

Unfortunately I couldn't find a method to do this.

jasonwryan
  • 71,734
  • 34
  • 193
  • 226

2 Answers2

10

For commands with little output and short lines you can do that easily with a combination of a2ps, ghostscript and imagemagick:

Here the output of the command ls is used as an example.

ls | 
a2ps -=book -B -q --medium=A4dj --borders=no -o out1.ps &&
gs \
  -sDEVICE=png256           \
  -dNOPAUSE -dBATCH -dSAFER \
  -dTextAlphaBits=4 -q      \
  -r300x300                 \
  -sOutputFile=out2.png out1.ps
convert -trim out2.png result.png

a2ps creates a vector image of the text. ghostscript rasterises it into a PNG graphic (don't use JPEG, it's the wrong graphic format for this, it's only useful for photorealistic images). Finally imagemagick is used to remove the surrounding white space. Read the man pages and tweak the parameters as necessary.

If the programs are not installed, you can compile and install them with --prefix=/home/me/.local as a user without admin rights.

EDIT: As mentioned in a comment a solution without the dependency of a2ps and ghostscript is the following one.

convert label:"$(ls)" result.png
Marco
  • 33,188
  • 10
  • 112
  • 146
0

You use an online website to convert your terminal output to an image.

  1. https://carbon.now.sh/
  2. https://ray.so/

Both websites are free and easy to use. You copy your terminal output and paste one of the website editor sections. After clicking to export, your code successfully converts to a beautiful image.

Look like

enter image description here

AdminBee
  • 21,637
  • 21
  • 47
  • 71
  • Those are fancy for source code but when you want to generate an image of terminal output you'll get only plaintext as syntax highlight. I found none that support shell/ANSI escape codes. – noraj Feb 05 '23 at 21:05