Last active
July 26, 2019 23:16
-
-
Save antonfirsov/08f73989c9ce1861e1381ca67673b1b1 to your computer and use it in GitHub Desktop.
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
public void RunThisOnYourDevice() | |
{ | |
string inputImagesRoot = "YourRootToImages"; // https://github.com/SixLabors/ImageSharp/tree/master/tests/Images/Input | |
string reportFile = Path.Combine("WhateverPathYouCanWriteTo", "Report.txt"); | |
string[] files = Directory.EnumerateFiles( | |
inputImagesRoot, | |
"*.*", | |
SearchOption.AllDirectories).Where( | |
f => Path.GetExtension(f).ToLower() == ".png" || Path.GetExtension(f).ToLower() == ".jpg" | |
|| Path.GetExtension(f).ToLower() == ".jpeg" | |
|| Path.GetExtension(f).ToLower() == ".bmp" | |
|| Path.GetExtension(f).ToLower() == ".gif") | |
.ToArray(); | |
using (var report = new StreamWriter(reportFile)) | |
{ | |
foreach (string file in files) | |
{ | |
report.WriteLine($"*** Testing {file} ..."); | |
try | |
{ | |
using (var img = Image.Load(file, out IImageFormat format)) | |
{ | |
} | |
report.WriteLine(" ... SUCCESS!"); | |
} | |
catch (NotSupportedException) | |
{ | |
report.WriteLine($" ... NotSupportedException (invalid input)"); | |
} | |
catch (ImageFormatException) | |
{ | |
report.WriteLine($" ... ImageFormatException (invalid input)"); | |
} | |
catch (Exception ex) | |
{ | |
report.WriteLine($"!!! FAILED: {ex.GetType().Name} : {ex.Message}"); | |
report.WriteLine(ex.StackTrace); | |
} | |
ms.Seek(0, SeekOrigin.Begin); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment