File tree Expand file tree Collapse file tree 2 files changed +24
-4
lines changed
Expand file tree Collapse file tree 2 files changed +24
-4
lines changed Original file line number Diff line number Diff line change @@ -2,7 +2,7 @@ function Resize-Image {
22 [CmdletBinding ()]
33 param (
44 [Parameter (Mandatory = $true )]
5- [ byte []] $Image ,
5+ $Image ,
66 [Parameter (Mandatory = $false , ParameterSetName = " Sizes" )]
77 [switch ]$ProportionalResize = $false ,
88 [Parameter (Mandatory = $true , ParameterSetName = " Sizes" )]
@@ -20,7 +20,13 @@ function Resize-Image {
2020 process {
2121 Write-Verbose " Cmdlet Resize-Image - Process"
2222
23- $stream = [System.IO.MemoryStream ]::new($Image )
23+ if ($Image.PSTypeNames -contains [System.Byte []].ToString()) {
24+ $stream = [System.IO.MemoryStream ]::new($Image )
25+ }
26+ else {
27+ $stream = $Image
28+ }
29+
2430 $img = [System.Drawing.Image ]::FromStream($stream )
2531
2632 if ($PSCmdlet.ParameterSetName -eq ' Sizes' ) {
Original file line number Diff line number Diff line change @@ -14,7 +14,7 @@ function Get-TestImage {
1414
1515 $result = [System.IO.MemoryStream ]::new()
1616 $bitmap.Save ($result , $Format )
17- $result.ToArray ()
17+ Write-Output $result.ToArray () - NoEnumerate
1818}
1919
2020function Convert-BytesToImage {
@@ -55,7 +55,6 @@ Describe 'Photo.Shell.Tests' {
5555 Context " Resize-Image" {
5656 $testImage = Get-TestImage
5757
58-
5958 It " should resize and keep ratio - smaller" {
6059 # 1000 x 800
6160 $img_before = Convert-BytesToImage $testImage
@@ -93,5 +92,20 @@ Describe 'Photo.Shell.Tests' {
9392 $img_after.Width | Should - BeExactly 200
9493 $img_after.Height | Should - BeExactly 160
9594 }
95+
96+ It " should accept" {
97+ $stream = [System.IO.MemoryStream ]::new($testImage )
98+ { Resize-Image - Image $stream - Ratio 1 } | Should -Not - Throw
99+ { Resize-Image - Image $stream - Ratio 1 } | Should -Not - BeNullOrEmpty
100+
101+ { Resize-Image - Image $testImage - Ratio 1 } | Should -Not - Throw
102+ { Resize-Image - Image $testImage - Ratio 1 } | Should -Not - BeNullOrEmpty
103+ }
104+
105+ It " shouldn't accept" {
106+ $stream = [System.IO.MemoryStream ]::new($testImage )
107+ $img = [System.Drawing.Image ]::FromStream($stream )
108+ { Resize-Image - Image $img - Ratio 1 } | Should - Throw
109+ }
96110 }
97111}
You can’t perform that action at this time.
0 commit comments