Created
June 10, 2015 09:57
-
-
Save SrcFlux/6274bcc1476a2ae77a96 to your computer and use it in GitHub Desktop.
Create image thumbnails with Power Shell
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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