Advertisement


Batch convert svg to psd


Question

I'm trying to use a bunch of svg icons on something I'm designing. Photoshop doesn't process svgs, apparently. I read Illustrator does and that I can just export it into psds. That much is managable but the problem is there are 300+ icons and I thought I'd just turn them all into psds in case I ever need them in the future.

How exactly do I do that? I'm using the CS5 suite.

2015/03/01
1
1
3/1/2015 5:12:00 PM

I suggest to use Inkscape and your command line to convert it to a png, jpg or whatever. Following command converts a single svg file to a 1024x1024px png:

inkscape -z -e test.png -w 1024 -h 1024 test.svg

Inkscape has mighty command line options, with the -z argument you can run inkscape headless (without a gui). You only have to pass your disired image format, dimensions and image name. See the docs for more information.

To Batch process a folder of svgs you can use a programming language of your choice and iterate through the files. I've used linux with python 2.7+ (platform independent) here:

import os # import os module
import subprocess # import subprocess module to call inkscape with python

# set the path to your svg folder
path = '/home/user/Desktop/svgs'   # linux or osx 
# path = r'c:\some\directory\svgs' # windows, the r is important
# path = 'c:/some/directory\svgs'  # windows (alternative)

# collect all svgs in this folder
svg_files = [f for f in os.listdir(path) if f.endswith('.svg')] 

# iterate through the files
for i in svg_files:
    # setup correct filepath for inkscape
    file_path = os.path.join(path,i)
    # generate file the with a png extension
    png_path = os.path.splitext(file_path)[0] + '.png'
    # call inkscape with the correct arguments like in the example above 
    subprocess.call(['inkscape', '-z', '-e', png_path, '-w 1024', '-h 1024', file_path])

To convert a png or whatever to psd file use ImageMagick. The command is simple:

convert test.png test.psd

See the docs for more information. Batch process the png files to psd files via python again:

import os # import os module
import subprocess # import subprocess module

# set the path to your svg folder
path = '/home/user/Desktop/pngs'    # linux or osx
# path = r'c:\some\directory\pngs'  # windows, the r is important
# path = 'c:/some/directory\pngs'   # windows (alternative)

# collect all pngs in this folder
png_files = [f for f in os.listdir(path) if f.endswith('.png')] 

# iterate through the files
for i in png_files:
    # setup correct filepath for pngs
    file_path = os.path.join(path,i)
    # generate file the with a psd extension
    psd_path = os.path.splitext(file_path)[0] + '.psd'
    # call imagemagick with the correct arguments
    subprocess.call(['convert', png_path, psd_path])

Generated files are working for me in Photoshop CS4+.

Note: Converting the files in one iteration is also possible of course, but I thought for illustration purposes it's easier to split up the process.

2015/06/05
2
6/5/2015 10:59:00 AM