public static void Run(LoadOptions options) { try { Console.WriteLine("Loading {0}", options.FileName); MemoryManagement.CheckMemory($"Before loading image(s) using {options.Mode}", true); if (options.Folder) { foreach (var file in System.IO.Directory.EnumerateFiles(options.FileName)) { if (Program.IsImageFile(file)) { LoadImageAndReport(options.Mode, file); } } } else { LoadImageAndReport(options.Mode, options.FileName); } MemoryManagement.CheckMemory("After disposing image(s)", true); } catch (Exception ex) { Console.WriteLine("EXCEPTION CAUGHT: {0}", ex); Console.WriteLine("{0}", ex.StackTrace); } }
internal static void Run(MetaOptions options) { try { Console.WriteLine("Extracting metadata from {0} using {1}", options.FileName, options.Mode); MemoryManagement.CheckMemory($"Before extracting metadata using {options.Mode}", true); if (options.Folder) { foreach (var file in System.IO.Directory.EnumerateFiles(options.FileName)) { if (Program.IsImageFile(file)) { LoadMetadataAndReport(options.Mode, file); } } } else { LoadMetadataAndReport(options.Mode, options.FileName); } MemoryManagement.CheckMemory("After metadata extracted and possibly discarded", true); } catch (Exception ex) { Console.WriteLine("EXCEPTION CAUGHT: {0}", ex); Console.WriteLine("{0}", ex.StackTrace); } }
private static void LoadMetadataAndReport(MetaMode mode, string filename) { Console.WriteLine("Image metadata from {0}", filename); switch (mode) { case MetaMode.MetadataExtractor: var metaDirectories = ImageMetadataReader.ReadMetadata(filename); foreach (var metaDir in metaDirectories) { foreach (var tag in metaDir.Tags) { Console.WriteLine($"{metaDir.Name}: \"{tag.Name}\" = \"{tag.Description}\""); } if (metaDir is XmpDirectory) { var properties = (metaDir as XmpDirectory).GetXmpProperties(); foreach (var prop in properties) { Console.WriteLine($" XMP \"{prop.Key}\" = \"{prop.Value}\""); } } } MemoryManagement.CheckMemory($"With metadata extracted using {mode}", true); break; case MetaMode.Palaso: var meta = SIL.Windows.Forms.ClearShare.Metadata.FromFile(filename); Console.WriteLine("meta.AttributionUrl = {0}", meta.AttributionUrl); Console.WriteLine("meta.CollectionName = {0}", meta.CollectionName); Console.WriteLine("meta.CollectionUri = {0}", meta.CollectionUri); Console.WriteLine("meta.CopyrightNotice = {0}", meta.CopyrightNotice); Console.WriteLine("meta.Creator = {0}", meta.Creator); Console.WriteLine("meta.License.Token = {0}", meta.License.Token); Console.WriteLine("meta.License.RightsStatement = {0}", meta.License.RightsStatement); Console.WriteLine("meta.License.Url = {0}", meta.License.Url); Console.WriteLine("meta.License.Description = {0}", meta.License.GetDescription(new[] { "en" }, out string langId)); Console.WriteLine("meta.ShortCopyrightNotice = {0}", meta.ShortCopyrightNotice); MemoryManagement.CheckMemory($"With metadata extracted using {mode}", true); break; case MetaMode.Taglib: var tagFile = TagLib.File.Create(filename); WriteTaglibValues(tagFile); MemoryManagement.CheckMemory($"With metadata extracted using {mode}", true); break; } }
private static void LoadImageAndReport(LoadMode mode, string filename) { switch (mode) { case LoadMode.System: using (var image = System.Drawing.Image.FromFile(filename)) { Console.WriteLine("{0} image size = {1}w by {2}h", System.IO.Path.GetFileName(filename), image.Width, image.Height); MemoryManagement.CheckMemory("With image loaded", true); } break; case LoadMode.Palaso: using (var image = SIL.Windows.Forms.ImageToolbox.PalasoImage.FromFile(filename)) { Console.WriteLine("{0} image size = {1}w by {2}h", System.IO.Path.GetFileName(filename), image.Image.Width, image.Image.Height); MemoryManagement.CheckMemory("With image loaded", true); } break; case LoadMode.ImageProcessor: using (var factory = new ImageProcessor.ImageFactory(true)) { factory.Load(filename); Console.WriteLine("{0} image size = {1}w by {2}h", System.IO.Path.GetFileName(filename), factory.Image.Width, factory.Image.Height); MemoryManagement.CheckMemory("With image loaded", true); } break; case LoadMode.ImageSharp: using (var image = SixLabors.ImageSharp.Image.Load(filename)) { Console.WriteLine("{0} image size = {1}w by {2}h", System.IO.Path.GetFileName(filename), image.Width, image.Height); MemoryManagement.CheckMemory("With image loaded", true); } break; } }