A PowerShell + FFmpeg script to generate WordPress-style thumbnails with enforced aspect ratio, cropping, format conversion, optional metadata, and per-dimension output folders.
Now supports height-based resizing as an alternative to width-based scaling.
Optimized for automation, performance, and precision.
- Multi-size output (e.g.
820x820,435x245,300x300) - Resizing based on width (default) or height
- Optional fixed aspect ratio (e.g.
1:1,16:9) - Format support:
webp,jpg,png - Optional per-width subfolders (e.g.
./thumbnails/435/) - Optional filename suffixes (e.g.
-md,-square) - Optional metadata embedding (
Software=WPThumbnailGenerator) - Overwrite protection and original file safeguard
- Fast execution using PowerShell call operator (
& ffmpeg) - FFmpeg/FFprobe required – no external modules
- PowerShell 5.1+ (recommended: PowerShell 7+)
- FFmpeg and FFprobe available in your system
PATH
# Width-based resize (default)
.\Generate-WordPress-Like-Thumbnails.ps1 `
-inputFolder ".\images" `
-outputFolder ".\thumbnails" `
-targetWidths @(820, 435, 300) `
-forceAspectRatio "1:1" `
-outputFormats @("webp", "jpg") `
-nameSuffix "square" `
-overwrite $true `
-addMetadata $true `
-usePerWidthSubfolder $true
# Height-based resize (alternative)
.\Generate-WordPress-Like-Thumbnails.ps1 `
-inputFolder ".\images" `
-outputFolder ".\thumbnails" `
-targetHeights @(600, 400) `
-outputFormats @("webp") `
-forceAspectRatio "4:3"| Name | Type | Description |
|---|---|---|
inputFolder |
string |
Source directory (default: .) |
outputFolder |
string |
Destination directory (default: .) |
targetWidths |
string[] |
List of target widths in pixels (mutually exclusive with heights) |
targetHeights |
string[] |
List of target heights in pixels (mutually exclusive with widths) |
outputFormats |
string[] |
Output formats (e.g. @("webp", "jpg")) |
forceAspectRatio |
string |
Aspect ratio like "1:1", "16:9" or $null |
nameSuffix |
string |
Optional suffix before dimensions (e.g. -md, -square) |
overwrite |
bool |
Overwrite existing thumbnails (default: true) |
addMetadata |
bool |
Embed metadata in output (default: false) |
usePerWidthSubfolder |
bool |
Output into outputFolder/width/ subfolders (default: true) |
validExtensions |
string[] |
Allowed input extensions (default: .jpg, .jpeg, .png, .webp) |
thumbnails/
├── 820/
│ └── image-square-820x820.webp
├── 435/
│ └── image-square-435x435.webp
targetWidthsandtargetHeightsare mutually exclusive.- Aspect ratio logic is respected for both width and height modes.
- Original files are never overwritten.