Created
April 4, 2025 15:21
-
-
Save hakanai/93540ea87a5cd7c325f9fb86413af535 to your computer and use it in GitHub Desktop.
Quick and dirty code to pull width and height from SVG files and compute how much to scale them
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
$maxsize = 96 | |
Get-ChildItem "*.svg" | ForEach-Object { | |
$xml = [xml](Get-Content $_.FullName) | |
$origWidth = [float][string]($xml | Select-Xml -XPath "/*/@width") | |
$origHeight = [float][string]($xml | Select-Xml -XPath "/*/@height") | |
$widthRatio = $maxsize / $origWidth | |
$heightRatio = $maxsize / $origHeight | |
$largerRatio = ($widthRatio,$heightRatio | Measure -Min).Minimum | |
$newWidth = $origWidth * $largerRatio | |
$newHeight = $origHeight * $largerRatio | |
New-Object psobject -Property @{ | |
Name = $_.Name | |
OrigWidth = $origWidth | |
OrigHeight = $origHeight | |
NewWidth = $newWidth | |
NewHeight = $newHeight | |
} | |
} | Format-Table |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment