Created
May 20, 2019 08:04
-
-
Save pepijnolivier/8f6917cc80e33d4779f9c83f4461590d to your computer and use it in GitHub Desktop.
SVG to PNG in Python
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# | |
# 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