Skip to content

Instantly share code, notes, and snippets.

@SrcFlux
Created June 10, 2015 09:57
Show Gist options
  • Save SrcFlux/6274bcc1476a2ae77a96 to your computer and use it in GitHub Desktop.
Save SrcFlux/6274bcc1476a2ae77a96 to your computer and use it in GitHub Desktop.
Create image thumbnails with Power Shell
Param (
[Parameter(Mandatory=$True)]
[string] $Type,
[Parameter(Mandatory=$True)]
[string] $Width,
[Parameter(Mandatory=$True)]
[string] $Height
)
[void][reflection.assembly]::LoadWithPartialName("System.Windows.Forms")
Get-ChildItem *.$Type | ForEach {
$fullPath = $(Resolve-Path $_).ToString()
$fullPath = $fullPath.Substring(0, $fullPath.LastIndexOf('.'));
$imageFile = "$($fullPath).$($Type)"
$thumbFile = "$($fullPath)_thumb.$($Type)"
if (! $imageFile) { "File '$imageFile' not found, exiting."; exit }
Write-Host $imageFile;
$image = [System.Drawing.Image]::FromFile($imageFile, $true);
$thumb = $image.GetThumbnailImage($Width, $Height, $null, [intptr]::Zero);
$thumb.Save($thumbFile);
$thumb.Dispose();
$image.Dispose();
Write-Host $thumbFile;
Write-Host
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment