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.

  • Take screenshots and edit them together on a more fully featured computer. – donothingsuccessfully Jun 20 '12 at 18:35

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           \
  -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
  • Thank you for your answer, but how as I indicated, I don't have permission to install new packages – Fernando Martinez Jun 20 '12 at 18:32
  • If you have imagemagick you could cut out the a2ps and just use convert label:"$( ls )" ls_output.png. I can't speak as to the aesthetics though. – donothingsuccessfully Jun 20 '12 at 18:33
  • @FernandoMartinez You don't need root privileges to install software, except if the home partition is mounted with noexec, but I've never seen a system in production where the users had no execute rights in their home directory. You should double-check that. – Marco Jun 20 '12 at 18:48
  • I didn't know this trick, I run "$(ls)" result.png, is it correct?, Do you have some examples?. Thank you. – Fernando Martinez Jun 20 '12 at 18:50
  • The example is printed on the gray area in my answer. You need the program convert from the imagemagick suite for that. – Marco Jun 20 '12 at 18:52

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.