Created
August 10, 2021 11:00
-
-
Save MitchellKehn/a3a0227a6450d644beec12f04a013dd7 to your computer and use it in GitHub Desktop.
[Batch Convert SVG-> PNG] uses PySide2 to convert SVGs to PNGs
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
from PySide2 import QtGui, QtSvg | |
import os | |
FOLDER = r"C:\Users\mkehn\Desktop\test_theme\theme\primary" | |
def convertPngToSvg(filepath, size): | |
folder, filename = os.path.split(filepath) | |
basename, ext = os.path.splitext(filename) | |
image = QtGui.QImage(size, size, QtGui.QImage.Format_ARGB32) | |
image.fill(0) | |
painter = QtGui.QPainter() | |
painter.begin(image) | |
renderer = QtSvg.QSvgRenderer() | |
renderer.load(filepath) | |
renderer.render(painter) | |
painter.end() | |
image.save(os.path.join(folder, basename+".png")) | |
for filename in os.listdir(FOLDER): | |
if filename.endswith("svg"): | |
convertPngToSvg(os.path.join(FOLDER, filename), 48) | |
print filename | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment