Text to SVG-File Shell Script

In an earlier posting I wrote, that I wanted to have a simple way to convert a few lines of plain-old-basic text, into an SVG-Image-File. In that posting I had created a set of templates, which would do so from the command-line, but which nevertheless required that the user do some work.

I also explained that the font-family “Liberation” needed to be installed on the machine, in order for that exact variant of the templates to be valid. And of course, ‘Inkscape’ must also be installed.

Well under Linux, if we’re given such templates, we can next proceed to write a shell-script, which does all the work for us, of assembling the templates, and then of executing some jobs.

Therefore, the only logical conclusion now was, that I created a Shell-Script, which I can enter as a command with the base-name, as the parameter to the script (without any .svg or .png extension), and which will expect some text from the standard input – Initially no more than 6 lines of 25 characters – and which creates the SVG as well as the PNG -Files. This script now works as expected. One finishes entering text with <Ctrl>+D .

The previous article described the theoretical basis on which this script works, and now I’m sharing the script with my readers – who are using Linux.

(Update 03/16/2018, 13h35 : )

I’ve refined my script, so that it allows the user to specify, optionally, a different text-color, a larger image-size if needed, and an external text-file to use as input, in that order. Also, my code now preserves spaces in the input-text, and escape-codes certain dangerous characters, if fed in through an external text-file.

visual

anglebs

 

(Update 03/25/2018 : )

I’ve updated my script again. In general, it’s not good for any ‘program’ to have too many dependencies, and the previous version of this script depended on ‘tr’, ‘wc’, ‘sed’, and ‘gawk’, as well as on ‘Inkscape’. While this worked fine on my own computer, it doesn’t serve my potential readers well, who may not want to have all that installed, just to use my script. And so by now, I’ve removed the dependency on ‘gawk’, because what it did, ‘sed’ can do as well.

Dirk

 

Print Friendly, PDF & Email

4 thoughts on “Text to SVG-File Shell Script”

  1. Very handy script. Saved me quite a bit of time. Inkscape dependency is still there, I think. At least it complains about it, but still seems to work. Thanks!

    1. The way the script is written, it sets the path to each dependency at the beginning. The path to Inkscape is stored in the variable ‘EXEC’, and if the program at that location is not executable, my script cannot work.

      Try the following command:
      which inkscape

      What this should output is the location of your Inkscape executable. If appropriate, modify my script, to set the variable ‘EXEC’ to the correct path, with the name of the program, being sure to keep the single quotes. If you don’t have Inkscape installed, you’ll need to install it, in order for my script to work.

      Dirk

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

 

This site uses Akismet to reduce spam. Learn how your comment data is processed.