add some things to exif output

This commit is contained in:
Colin McMillen 2023-07-28 17:54:00 -04:00
parent 831637338c
commit c74d5c5385

View File

@ -231,10 +231,24 @@ public class Photo {
Directory.CreateDirectory(directory); Directory.CreateDirectory(directory);
string filename = System.IO.Path.Combine(directory, System.IO.Path.GetFileName(Filename)); string filename = System.IO.Path.Combine(directory, System.IO.Path.GetFileName(Filename));
Console.WriteLine("saving " + 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? // FIXME: warn if the file already exists?
using (Image<Rgba32> image = await Image.LoadAsync<Rgba32>(Filename)) { using (Image<Rgba32> image = await Image.LoadAsync<Rgba32>(Filename)) {
// Util.RotateImageFromExif(image, Orientation); Util.RotateImageFromExif(image, Orientation);
ExifProfile exif = image.Metadata.ExifProfile ?? new();
exif.SetValue<ushort>(ExifTag.Orientation, 1);
exif.SetValue<string>(ExifTag.Artist, "Colin McMillen");
exif.SetValue<string>(ExifTag.Copyright, "Colin McMillen");
exif.SetValue<string>(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<string>(ExifTag.DateTime, datetime);
await image.SaveAsync(filename, encoder); await image.SaveAsync(filename, encoder);
} }
} }
@ -285,6 +299,8 @@ public class Photo {
// Modification Date/Time Modification date of the digital image file // Modification Date/Time Modification date of the digital image file
// Exif DateTime (306, 0x132) and SubSecTime (37520, 0x9290) // Exif DateTime (306, 0x132) and SubSecTime (37520, 0x9290)
// XMP (xmp:ModifyDate) // XMP (xmp:ModifyDate)
//
// See also: https://exiftool.org/TagNames/EXIF.html
private void ParseExif(ExifProfile? exifs) { private void ParseExif(ExifProfile? exifs) {
if (exifs == null) { if (exifs == null) {
return; return;
@ -322,6 +338,7 @@ public class Photo {
} }
} }
// FIXME: could also show ExposureBiasValue, ExposureMode, ExposureProgram?
IExifValue<Rational>? exposureTime; IExifValue<Rational>? exposureTime;
if (exifs.TryGetValue(ExifTag.ExposureTime, out exposureTime)) { if (exifs.TryGetValue(ExifTag.ExposureTime, out exposureTime)) {
Rational r = exposureTime.Value; Rational r = exposureTime.Value;
@ -804,8 +821,9 @@ public class Game : GameWindow {
// Load photos from a directory. // Load photos from a directory.
// string[] files = Directory.GetFiles(@"c:\users\colin\desktop\photos-test\"); // 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(@"c:\users\colin\pictures\photos\2023\07\14\");
// string[] files = Directory.GetFiles(@"G:\DCIM\100EOSR6\"); 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\Pictures\photos\2018\06\23");
// string[] files = Directory.GetFiles(@"C:\Users\colin\Desktop\Germany all\104D7000"); // string[] files = Directory.GetFiles(@"C:\Users\colin\Desktop\Germany all\104D7000");
// string[] files = Directory.GetFiles(@"C:\Users\colin\Desktop\many-birds\"); // string[] files = Directory.GetFiles(@"C:\Users\colin\Desktop\many-birds\");
@ -894,7 +912,6 @@ public class Game : GameWindow {
JpegEncoder encoder = new JpegEncoder() { Quality = 100 }; JpegEncoder encoder = new JpegEncoder() { Quality = 100 };
string outputRoot = @"c:\users\colin\desktop\totte-output"; string outputRoot = @"c:\users\colin\desktop\totte-output";
foreach (Photo p in photos) { foreach (Photo p in photos) {
// p.SaveAsJpeg(outputRoot, encoder);
await Task.Run( () => { p.SaveAsJpeg(outputRoot, encoder); }); await Task.Run( () => { p.SaveAsJpeg(outputRoot, encoder); });
} }
} }