Posted by CANbike on Thu, 6 Mar 2014

Images: Batch Convert SVG Vector Files to PNG

Inkscape, an open source SVG (Scalable Vector Graphics) editing program, can be run from the command line; which is useful for exporting files.

Inkscape Command Line

The following is a command to convert “filename.svg” to a 2000 pixel wide PNG file.

inkscape -z -w 2000 -e filename.png filename.svg

where

z - Does not open the GUI and only processes the files from console.
w - Sets the width of generated bitmap in pixels.
    The value overrides the --export-dpi setting.
e - Specifies the filename for PNG export.

Batch Convert SVG to PNG

To batch process SVG files to PNG files, the find command

find -iname "*.svg*

will perform a cases insensitive search for files ending with “.svg”.

Adding the -exec option, arguments found will be passed onto the specified command; in this case, inkscape. The special characters \; signal the end of the specified command.

The following command batch exports SVG files to PNG files.

find -iname "*.svg" -exec inkscape -z -w 2000 -e "{}".png "{}" \;

where

iname - Sets the case insensitive search pattern.
exec  - Passes arguments onto a command.
"{}"  - Represents an argument found.
"\;"  - Specifies the end of the command to execute.

Batch Convert SVG to PNG-01-thumb.pngBatch Convert SVG to PNG-02-thumb.pngBatch Convert SVG to PNG-03-thumb.png


Related Item(s):