Created
May 22, 2014 19:11
-
-
Save cdhunt/639cdbc5c93f1ca8a23b to your computer and use it in GitHub Desktop.
Posh Wrapper for the .Net ImageProcessor library
This file contains hidden or 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
<# | |
.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 | |
} | |
} |
Author
cdhunt
commented
May 22, 2014
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