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

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

September 22nd, 2011 Leave a comment Go to comments

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 ./cmd2png.sh 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 cmd2png.sh then run the script as follows:

./cmd2png.sh “ifconfig eth0″ “ifconfig_cmd.png”

Those commands were tried in Ubuntu 10.04 LTS.

Digg This
Reddit This
Stumble Now!
Buzz This
Vote on DZone
Share on Facebook
Bookmark this on Delicious
Kick It on DotNetKicks.com
Share on LinkedIn
Bookmark this on Technorati
Post on Twitter

  1. February 9th, 2012 at 06:32 | #1
  2. June 10th, 2015 at 03:24 | #2

    VERY helpful, even after this long time…
    All the other ways like batching GIMP, ImageMagick oder phatch have neither an easy way nor any good example how to add text to a wallpaper in a simple way.
    After hours of searching, installing and trying here I am – THANK YOU!
    Your help esulted in this little script:
    # gather some info and store it as text in ~/sysinfo.txt
    # especially to fill a text box on a wallpaper with GIMP
    echo > ~/sysinfo.txt
    echo >> ~/sysinfo.txt
    echo >> ~/sysinfo.txt
    echo >> ~/sysinfo.txt
    date >> ~/sysinfo.txt
    uname -o >> ~/sysinfo.txt # OS
    uname -n >> ~/sysinfo.txt # Rechner
    uname -s -r >> ~/sysinfo.txt # Kernel & Release
    uname -v >> ~/sysinfo.txt # Version
    uname -p >> ~/sysinfo.txt
    bash –version > /tmp/bashversion
    head -1 /tmp/bashversion >> ~/sysinfo.txt
    ls /home >> ~/sysinfo.txt # User
    lscpu >> ~/sysinfo.txt
    df -h >> ~/sysinfo.txt
    cinnamon –version >> ~/sysinfo.txt
    xrandr >> ~/sysinfo.txt

    cat ~/sysinfo.txt | convert -size 1680×1050 -roll x+1100 -background black -fill DeepSkyBlue -font Ubuntu-Mono-Regular -pointsize 12 label:@- ~/.cinnamon/backgrounds/sysinfo.png

    If you use it, don’t forget to change the last folder/file to your own wallpaper folder and switch the wallpaper once after first run.
    The first empty echoes were needed because I couldn’t find out how to shift the text a little lower (my task bar is on top), but I don’t mind.
    I added a cron job which call this script every 30 min.

    You could add command
    convert -list color
    to improve the list above.

  1. No trackbacks yet.