Skip to content

Instantly share code, notes, and snippets.

@pepijnolivier
Created May 20, 2019 08:04
Show Gist options
  • Save pepijnolivier/8f6917cc80e33d4779f9c83f4461590d to your computer and use it in GitHub Desktop.
Save pepijnolivier/8f6917cc80e33d4779f9c83f4461590d to your computer and use it in GitHub Desktop.
SVG to PNG in Python
#
# Usage:
# - have all svg's in a particular folder
# - cd into that folder
# - call the script with the desired size as a parameter
# python svg-to-png.py 500
#
#
import glob
import os
import sys
size = str(sys.argv[1])
targetDirectory = "."
os.chdir(targetDirectory)
# 2. create folder {size} if it does not exist yet
command = "mkdir -p " + size
os.system(command)
for file in glob.glob("*.svg"):
# outputPath = "./" + size + "/" + filename.svg
folder = size + "/"
newfile = folder + file + ".png"
command = "rsvg-convert -h " + size + " " + file + " > " + newfile
print command
# command = "qlmanage -t -s 1000 -o . " + file
os.system(command)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment