Skip to content

Instantly share code, notes, and snippets.

@cdhunt
Created May 22, 2014 19:11
Show Gist options
  • Save cdhunt/639cdbc5c93f1ca8a23b to your computer and use it in GitHub Desktop.
Save cdhunt/639cdbc5c93f1ca8a23b to your computer and use it in GitHub Desktop.
Posh Wrapper for the .Net ImageProcessor library
<#
.Synopsis
Short description
.DESCRIPTION
Long description
.EXAMPLE
Example of how to use this cmdlet
.EXAMPLE
Another example of how to use this cmdlet
#>
function Get-ImageStream
{
[CmdletBinding()]
[OutputType([ImageProcessor.ImageFactory])]
Param
(
# Param1 help description
[Parameter(Mandatory=$true,
ValueFromPipelineByPropertyName=$true,
Position=0)]
$Path
)
[byte[]]$photoBytes = ([IO.File]::ReadAllBytes($Path))
[int]$quality = 70
#ImageFormat format = ImageFormat.Jpeg;
#Size size = new Size(150, 0)
$inStream = New-Object IO.MemoryStream(,$photoBytes)
$imageFactory = New-Object ImageProcessor.ImageFactory
$null = $imageFactory.Load($inStream)
Write-Output -InputObject $imageFactory
}
<#
.Synopsis
Short description
.DESCRIPTION
Long description
.EXAMPLE
Example of how to use this cmdlet
.EXAMPLE
Another example of how to use this cmdlet
#>
function Set-ImageSize
{
[CmdletBinding()]
[OutputType([ImageProcessor.ImageFactory])]
Param
(
# Param1 help description
[Parameter(Mandatory,ValueFromPipeline,Position=0)]
[ImageProcessor.ImageFactory]
$InputObject,
[Parameter(Mandatory,Position=1)]
[int]
$Width,
[Parameter(Mandatory,Position=2)]
[int]
$Height
)
Begin
{
$size = New-Object System.Drawing.Size($Width, $Height)
}
Process
{
$_.Resize($size) | Write-Output
}
}
<#
.Synopsis
Short description
.DESCRIPTION
Long description
.EXAMPLE
Example of how to use this cmdlet
.EXAMPLE
Another example of how to use this cmdlet
#>
function Save-Image
{
[CmdletBinding()]
[OutputType([ImageProcessor.ImageFactory])]
Param
(
# Param1 help description
[Parameter(Mandatory,ValueFromPipeline,Position=0)]
[ImageProcessor.ImageFactory]
$InputObject,
[Parameter(Mandatory,Position=1)]
[string]
$Path
)
Process
{
$_.Save($Path) | Write-Output
}
}
@cdhunt
Copy link
Author

cdhunt commented May 22, 2014

Get-ImageStream C:\temp\Capture.PNG | 
   Set-ImageSize -Width 100 -Height 100 | 
   Save-Image -Path c:\temp\captureresize.png 

@pcgeek86
Copy link

Line 29:

$inStream = New-Object -TypeName IO.MemoryStream -ArgumentList @(,$photoBytes);

Cheers,
Trevor Sullivan
Microsoft PowerShell MVP

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment