@@ -17,6 +17,16 @@ function Get-TestImage {
1717 $result.ToArray ()
1818}
1919
20+ function Convert-BytesToImage {
21+ param (
22+ [byte []]$testImage
23+ )
24+
25+ $stream = [System.IO.MemoryStream ]::new($testImage )
26+ [System.Drawing.Image ]::FromStream($stream )
27+
28+ }
29+
2030Describe ' Photo.Shell.Tests' {
2131 Context " Get-ImageCodecInfo" {
2232 $testImage = Get-TestImage
@@ -41,4 +51,47 @@ Describe 'Photo.Shell.Tests' {
4151 Get-ImageCodecInfo $img | Select-Object - ExpandProperty MimeType | Should - BeExactly $Expected
4252 }
4353 }
54+
55+ Context " Resize-Image" {
56+ $testImage = Get-TestImage
57+
58+
59+ It " should resize and keep ratio - smaller" {
60+ # 1000 x 800
61+ $img_before = Convert-BytesToImage $testImage
62+
63+ $img_after = Resize-Image - Image $testImage - Ratio 0.1 # 10%
64+ $img_after = [System.Drawing.Image ]::FromStream($img_after )
65+
66+ $img_after.Width | Should - BeExactly ($img_before.Width * 0.1 )
67+ $img_after.Height | Should - BeExactly ($img_before.Height * 0.1 )
68+ }
69+
70+ It " should resize and keep ratio - bigger" {
71+ # 1000 x 800
72+ $img_before = Convert-BytesToImage $testImage
73+
74+ $img_after = Resize-Image - Image $testImage - Ratio 1.2 # 120%
75+ $img_after = [System.Drawing.Image ]::FromStream($img_after )
76+
77+ $img_after.Width | Should - BeExactly ($img_before.Width * 1.2 )
78+ $img_after.Height | Should - BeExactly ($img_before.Height * 1.2 )
79+ }
80+
81+ It " should resize to a given size" {
82+ $img_after = Resize-Image - Image $testImage - Width 200 - Height 200
83+ $img_after = [System.Drawing.Image ]::FromStream($img_after )
84+
85+ $img_after.Width | Should - BeExactly 200
86+ $img_after.Height | Should - BeExactly 200
87+ }
88+
89+ It " should resize to a given size with ratio" {
90+ $img_after = Resize-Image - Image $testImage - Width 200 - Height 200 - ProportionalResize
91+ $img_after = [System.Drawing.Image ]::FromStream($img_after )
92+
93+ $img_after.Width | Should - BeExactly 200
94+ $img_after.Height | Should - BeExactly 160
95+ }
96+ }
4497}
0 commit comments