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.

WindowsimagethumbnailpowershellLow risk
Load the image, create a Bitmap at the target size, DrawImage it with HighQualityBicubic interpolation, then save the bitmap.

01Command

Command
$ 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

RiskLow risk
RequirementsWindows PowerShell 5.1 (System.Drawing requires .NET Framework, i.e. powershell.exe not pwsh)

04Undo

✓No undo needed — this command does not change persistent state.

05Sources

  • Graphics.DrawImage Method (System.Drawing)
    Microsoft Learn · vendor-doc · 2026-09-17
    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)
    Microsoft Learn · vendor-doc · 2026-09-17
    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