Created
May 17, 2021 06:24
-
-
Save mawiseman/4762c07c550cb629e53896cb9284a709 to your computer and use it in GitHub Desktop.
Users powershell to convert batch convert svg to png
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
cls | |
# CONSTANTS | |
$inkscapePath = "C:\Program Files\Inkscape\bin\inkscape.com" | |
# Get files to process | |
$sourcePath ="[[UPDATE WITH YOUR PAT]]" | |
$sourceFiles = Get-ChildItem -Path $sourcePath -File -Recurse -Filter *.svg | |
# Convert all files | |
ForEach ($sourceFile in $sourceFiles) | |
{ | |
# processing File | |
$processingFile = $sourceFile.FullName -replace [regex]::Escape($sourcePath), "" | |
# Ensure the target folder exists | |
$targetPath = $sourceFile.Directory -replace [regex]::Escape($sourcePath), $rootTargetPath | |
$result = New-Item -ItemType Directory -Force -Path $targetPath | |
# Convert using Inkscape | |
$targetFilePath = Join-Path $targetPath $sourceFile | |
$targetFilePath = $targetFilePath -replace ".svg", ".png" | |
if(Test-Path $targetFilePath) | |
{ | |
Write-Host "Skipping: $processingFile" | |
} | |
else | |
{ | |
Write-Host "Processing: $processingFile" | |
# NOTE: without '$result =' & 2>&1 we get a lot of errors... that dont appear to affect anything | |
$result = & $inkscapePath --export-dpi=300 --export-filename $targetFilePath $sourceFile.FullName 2>&1 | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment