Last active
January 17, 2022 10:48
-
-
Save curtisgibby/ebac612657d6ef71a32fe03e75bd07cf to your computer and use it in GitHub Desktop.
Powershell script to use imagemagick to convert a directory of SVGs to PNGs (with 10% padding)
This file contains hidden or 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
$svgs = Get-ChildItem (".\*") -Filter *.svg | |
$scriptPath = $MyInvocation.MyCommand.Path | |
$scriptDirectory = Split-Path $scriptPath | |
$outputDirectory = $scriptDirectory + "\output" | |
# Replace specific path as needed | |
$magickExePath = "C:\Program Files\ImageMagick-7.0.8-Q16\magick.exe" | |
ForEach($svg in $svgs) { | |
Write-Host $svg | |
$svgQuoted = '"' + $svg + '"' | |
$outputFile = Split-Path $svg.Basename -leaf | |
$outputFile = $outputFile + '.png' | |
$pngPath = Join-Path -Path $outputDirectory -ChildPath $outputFile | |
$pngPath = '"' + $pngPath + '"' | |
$arguments = 'convert','-scale','500x500','-extent','110%x110%','-gravity','center','-background','transparent',$svgQuoted,$pngPath | |
& $magickExePath $arguments | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
How would I change this script to make image conversion RECURSIVE for all subfolders as well?