From c74d5c538557bc58179dc95ce7b55cfae5620e0a Mon Sep 17 00:00:00 2001 From: Colin McMillen Date: Fri, 28 Jul 2023 17:54:00 -0400 Subject: [PATCH] add some things to exif output --- Program.cs | 27 ++++++++++++++++++++++----- 1 file changed, 22 insertions(+), 5 deletions(-) diff --git a/Program.cs b/Program.cs index 8e67b62..47f95e5 100644 --- a/Program.cs +++ b/Program.cs @@ -231,10 +231,24 @@ public class Photo { Directory.CreateDirectory(directory); string filename = System.IO.Path.Combine(directory, System.IO.Path.GetFileName(Filename)); Console.WriteLine("saving " + filename); - // FIXME: update JPEG metadata. + // FIXME: update Rating data. + // FIXME: add comments / captions as ImageDescription? + // FIXME: strip some Exif tags for privacy reasons? // FIXME: warn if the file already exists? using (Image image = await Image.LoadAsync(Filename)) { - // Util.RotateImageFromExif(image, Orientation); + Util.RotateImageFromExif(image, Orientation); + + ExifProfile exif = image.Metadata.ExifProfile ?? new(); + exif.SetValue(ExifTag.Orientation, 1); + exif.SetValue(ExifTag.Artist, "Colin McMillen"); + exif.SetValue(ExifTag.Copyright, "Colin McMillen"); + exif.SetValue(ExifTag.Software, "Totte"); + DateTime now = DateTime.Now; + string datetime = String.Format( + "{0:D4}:{1:D2}:{2:D2} {3:D2}:{4:D2}:{5:D2}", + now.Year, now.Month, now.Day, now.Hour, now.Minute, now.Second); + exif.SetValue(ExifTag.DateTime, datetime); + await image.SaveAsync(filename, encoder); } } @@ -285,6 +299,8 @@ public class Photo { // Modification Date/Time – Modification date of the digital image file // Exif DateTime (306, 0x132) and SubSecTime (37520, 0x9290) // XMP (xmp:ModifyDate) + // + // See also: https://exiftool.org/TagNames/EXIF.html private void ParseExif(ExifProfile? exifs) { if (exifs == null) { return; @@ -322,6 +338,7 @@ public class Photo { } } + // FIXME: could also show ExposureBiasValue, ExposureMode, ExposureProgram? IExifValue? exposureTime; if (exifs.TryGetValue(ExifTag.ExposureTime, out exposureTime)) { Rational r = exposureTime.Value; @@ -804,8 +821,9 @@ public class Game : GameWindow { // Load photos from a directory. // string[] files = Directory.GetFiles(@"c:\users\colin\desktop\photos-test\"); - string[] files = Directory.GetFiles(@"c:\users\colin\pictures\photos\2023\07\14\"); - // string[] files = Directory.GetFiles(@"G:\DCIM\100EOSR6\"); + // string[] files = Directory.GetFiles(@"c:\users\colin\pictures\photos\2023\07\14\"); + string[] files = Directory.GetFiles(@"G:\DCIM\100EOSR6\"); + // string[] files = Directory.GetFiles(@"c:\users\colin\desktop\totte-output\2023\07\28"); // string[] files = Directory.GetFiles(@"C:\Users\colin\Pictures\photos\2018\06\23"); // string[] files = Directory.GetFiles(@"C:\Users\colin\Desktop\Germany all\104D7000"); // string[] files = Directory.GetFiles(@"C:\Users\colin\Desktop\many-birds\"); @@ -894,7 +912,6 @@ public class Game : GameWindow { JpegEncoder encoder = new JpegEncoder() { Quality = 100 }; string outputRoot = @"c:\users\colin\desktop\totte-output"; foreach (Photo p in photos) { - // p.SaveAsJpeg(outputRoot, encoder); await Task.Run( () => { p.SaveAsJpeg(outputRoot, encoder); }); } }