How-to Convert a Command Line Result into an Image in Linux

Here’s a technique to convert a command line result into an image in Linux using ImageMagick.

You could also do a screenshot (with PrtSrc key) and use Gimp to trim the image, but this method is faster and does not require a graphical interface.

command line to PNG example
Result of ./ ifconfig ifconfig_cmd.png

The simplest command to convert the result of ifconfig into an image:

ifconfig | convert label:@- cmd.png

This will give an image with a white background and black text, but If you want to have a black background with white text you can use the following:

ifconfig | convert -background black -fill white \
label:@- cmd.png

If you want to change the font and the font size:

ifconfig | convert -background black -fill white \
-font Helvetica -pointsize 14 \
label:@- cmd.png

You can retrieve the list of fonts with this command:

convert -list font | grep Font:

Finally, use this command to add an extra black border for a better looking image:

ifconfig | convert -background black -fill white \
-font Helvetica -pointsize 14 \
-border 10 -bordercolor black \
label:@- cmd.png

If you are always going to use this command often and always apply the same style, you could also write a script:


$1 | convert -background black -fill white \
-font Helvetica -pointsize 14 \
-border 10 -bordercolor black \
label:@- $2

Let’s name the script then run the script as follows:

./ “ifconfig eth0” “ifconfig_cmd.png”

Those commands were tried in Ubuntu 10.04 LTS.

Share this:

Support CNX Software! Donate via cryptocurrencies or become a Patron on Patreon

ROCK Pi 4C Plus
Notify of
The comment form collects your name, email and content to allow us keep track of the comments placed on the website. Please read and accept our website Terms and Privacy Policy to post a comment.
Weller PCB manufacturer