Skip to content

Instantly share code, notes, and snippets.

@hakanai
Created April 4, 2025 15:21
Show Gist options
  • Save hakanai/93540ea87a5cd7c325f9fb86413af535 to your computer and use it in GitHub Desktop.
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
$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