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.
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:
#!/bin/sh
$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.
Jean-Luc started CNX Software in 2010 as a part-time endeavor, before quitting his job as a software engineering manager, and starting to write daily news, and reviews full time later in 2011.
Support CNX Software! Donate via cryptocurrencies, become a Patron on Patreon, or purchase goods on Amazon or Aliexpress
Thank you, it very useful. I found your post through reddit: http://www.reddit.com/r/commandline/comments/knozz/howto_convert_a_command_line_result_into_an_image/
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: #——————————————- #!/bin/bash # 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 >>… Read more »
Of course my comment “GIMP” is fault – left over from an older version where I tried to use the gimp command line interface (without positive results). Sorry for that.
Btw., in Ubuntu 15(?) and so in my Linux Mint 18 (and I guess aready in 17.3) policies had been changed for security reasons so that the “label:@-“parameter doesn’t work anymore; a manual change of this policies was not succesful yet. :-((