Read image dimensions in PowerShell with System.Drawing
Load any JPG/PNG/BMP into a System.Drawing.Image and read Width and Height — the quick, native way to check image sizes in scripts.
01Command
$ Add-Type -AssemblyName System.Drawing; $img=[System.Drawing.Image]::FromFile('C:\Pictures\photo.jpg'); "$($img.Width) x $($img.Height)"; $img.Dispose()02What it does
FromFile decodes just enough of the file to expose properties like Width, Height, PixelFormat, and the raw file size — far faster than opening an editor for a sanity check. Always call Dispose() (or wrap in try/finally) because FromFile keeps the file locked until then, which breaks later rename/move operations. Loop over Get-ChildItem *.jpg to build a dimension report, and note this needs Windows PowerShell 5.1 or the Microsoft.Windows.Compatibility pack under PowerShell 7.
03Risk
04Undo
✓No undo needed — this command does not change persistent state.
05Sources
- Image Class (System.Drawing) | Microsoft LearnEvidence: Microsoft documents System.Drawing.Image with FromFile and Width/Height properties for reading image dimensions.
Last verified: 2026-09-17 · Category: Media
06Related solutions
Search inside text files and logs with regex, returning file, line number and match.
Create or update a .zip from any files or folder contents straight from PowerShell.
A built-in PowerShell one-liner that answers 'is port 5432/3389/443 actually open through this network?' — no telnet client needed.