user6340614
user6340614

Reputation:

How to convert a folder with SVG files to PNG with inkscape linux?

I have in my image folders in my WordPress installation a few thousands of SVG files and I would like to convert all images now to PNG to display them instead of the SVG file on my website. I would like to use inkscape to conert the images with some good compression.

How can I convert the whole folder into PNG file with a given high where all images have the same name as before? Like test49.svg will be test49.png.

I have tried a few plugins for WordPress with PNG fallback option but they didn't success.

Upvotes: 2

Views: 7584

Answers (3)

Moini
Moini

Reputation: 1387

The tags suggest you want to use Inkscape for it. Have a look at the command line options, by typing 'man inkscape' on the terminal, or by visiting https://inkscape.org/doc/inkscape-man.html .

To convert a single image, do

inkscape filename.svg --export-png=filename.png

To convert multiple images, you can combine the inkscape command with find.

Go into the folder with your svg images and do

find -name "*.svg" -exec sh -c 'inkscape $1 --export-png=${1%.svg}.png' _ {} \;

If you then still need to resize the pictures, use imagemagick's mogrify for that.

Upvotes: 5

fmw42
fmw42

Reputation: 53081

You can process a whole folder of SVG files using Imagemagick, which will offload the work to Inkscape, if it is on your system (at least for versions 6.7.9-0 or higher).

Imagemagick comes with Linux systems and is also available for Mac OSX or Windows.

Using Imagemagick 6:

Change directories to your folder containing the SVG files, then

mogrify -format png -colorspace sRGB -density XXX *.svg

That command will create the same file names but with .png suffix and place them in the same directory.

If you want to put the PNGs in a different directory, create one (e.g. pngfolder), then

mogrify -format png -path path_to/pngfolder -colorspace sRGB -density XXX  *.svg


That command will put the resulting PNGs in folder pngfolder.

If on Imagemagick 7, put magick before mogrify.

Set the density for whatever output size you want. Later versions of Inkscape have a default density of 96, so if you want your PNG to be twice as large as the default rendering of the SVG, use 2*96=192, etc.

If you want high quality PNGs at the default density then use -density 384 and add -resize 25% right after that (where 384=4*96 and 25%=1/4)

Upvotes: 3

Apache00
Apache00

Reputation: 5

I can imagine it would be possible to write a keyboard macro. First, figure out what keys need to be pressed to do the job for one file, for example in the file browser press Enter to open, then Ctrl-Shift+S to save as, then use tab to set everything up, ... Then write a short program that triggers the sequence repeatedly until all images are done. Or use an existing program that lets you enter macros. Take care to leave enough time between the key strokes for loading.

Or check the internet if there are any converter programs available, they can convert many files, too.

Upvotes: -3

Related Questions