File tree Expand file tree Collapse file tree 1 file changed +31
-1
lines changed
Expand file tree Collapse file tree 1 file changed +31
-1
lines changed Original file line number Diff line number Diff line change 11using EmailPreviewServices ;
2+ using SixLabors . ImageSharp ;
3+ using SixLabors . ImageSharp . PixelFormats ;
4+ using SixLabors . ImageSharp . Processing ;
25
36[ TestFixture ]
47public class Samples
@@ -80,8 +83,35 @@ Get Started
8083 await Task . Delay ( delay ) ;
8184 }
8285
86+
87+ using var image = await Image . LoadAsync < Rgba32 > ( streamAsync ) ;
88+
89+ var cropHeight = image . Height ;
90+ for ( var y = image . Height - 1 ; y >= 0 ; y -- )
91+ {
92+ var hasContent = false ;
93+ for ( var x = 0 ; x < image . Width ; x ++ )
94+ {
95+ var pixel = image [ x , y ] ;
96+ if ( pixel . R < 240 || pixel . G < 240 || pixel . B < 240 )
97+ {
98+ hasContent = true ;
99+ break ;
100+ }
101+ }
102+ if ( hasContent )
103+ {
104+ cropHeight = y + 1 ;
105+ break ;
106+ }
107+ }
108+
109+ image . Mutate ( ctx => ctx . Crop ( image . Width , cropHeight ) ) ;
110+ var memoryStream = new MemoryStream ( ) ;
111+ await image . SaveAsPngAsync ( memoryStream ) ;
112+ memoryStream . Position = 0 ;
83113 await service . DeletePreviewAsync ( preview . Id ) ;
84- await Verify ( streamAsync , extension : "png" ) ;
114+ await Verify ( memoryStream , extension : "png" ) ;
85115 // await using var streamAsync = await httpClient.GetStreamAsync(preview.Body);
86116 // await using var fileStream = File.Create("temp.html");
87117 // await streamAsync.CopyToAsync(fileStream);
You can’t perform that action at this time.
0 commit comments