Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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

This comment has been minimized.

Copy link
Owner 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

This comment has been minimized.

Copy link

pcgeek86 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
You can’t perform that action at this time.