Skip to content

Instantly share code, notes, and snippets.

@mawiseman
Created May 17, 2021 06:24
Show Gist options
  • Save mawiseman/4762c07c550cb629e53896cb9284a709 to your computer and use it in GitHub Desktop.
Save mawiseman/4762c07c550cb629e53896cb9284a709 to your computer and use it in GitHub Desktop.
Users powershell to convert batch convert svg to png
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