Resize an Image to a Thumbnail with PowerShell
Scale a picture down (e.g. to 400px wide) with System.Drawing's Graphics.DrawImage in a single PowerShell command.
01Command
$ Add-Type -AssemblyName System.Drawing; $src=[System.Drawing.Image]::FromFile('C:\pics\photo.jpg'); $w=400; $h=[int]($src.Height*$w/$src.Width); $bmp=New-Object System.Drawing.Bitmap($w,$h); $g=[System.Drawing.Graphics]::FromImage($bmp); $g.InterpolationMode='HighQualityBicubic'; $g.DrawImage($src,0,0,$w,$h); $bmp.Save('C:\pics\photo-thumb.jpg'); $g.Dispose(); $bmp.Dispose(); $src.Dispose()02What it does
Drawing the source onto a new Bitmap gives control over interpolation quality, unlike naive Bitmap-with-size constructors. The height is computed from the original aspect ratio so nothing gets stretched. Wrap it in a foreach loop over Get-ChildItem to thumbnail a whole folder, and Dispose every object or files stay locked.
03Risk
04Undo
✓No undo needed — this command does not change persistent state.
05Sources
- Graphics.DrawImage Method (System.Drawing)Evidence: DrawImage is the documented way to render a source image at a new size onto a Bitmap, which is what makes this resize high quality.
- Image Class (System.Drawing)Evidence: Documents Image.FromFile for loading and the Width/Height properties used to compute the scaled aspect ratio.
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.