save raw/jpg/edits into separate directories

This commit is contained in:
Colin McMillen 2023-09-14 23:40:09 -04:00
parent ae0fa8f934
commit adc6bf7972
2 changed files with 28 additions and 9 deletions

View File

@ -4,6 +4,7 @@ using SixLabors.ImageSharp.Metadata.Profiles.Exif;
using SixLabors.ImageSharp.Metadata.Profiles.Xmp;
using SixLabors.ImageSharp.Formats;
using SixLabors.ImageSharp.Formats.Jpeg;
using static System.IO.Path;
using System.Text;
using System.Xml.Linq;
@ -160,20 +161,30 @@ public class Photo {
public async void SaveAsJpegAsync(string outputRoot, JpegEncoder encoder) {
// FIXME: if nothing was changed about this image, just copy the file bytes directly, possibly with metadata changed?
string directory = System.IO.Path.Combine(
string directory = Path.Combine(
outputRoot,
String.Format("{0:D4}", DateTimeOriginal.Year),
String.Format("{0:D2}", DateTimeOriginal.Month),
String.Format("{0:D2}", DateTimeOriginal.Day));
Directory.CreateDirectory(directory);
string filename = System.IO.Path.Combine(directory, System.IO.Path.GetFileName(Filename));
Directory.CreateDirectory(Path.Combine(directory, "1-raw"));
Directory.CreateDirectory(Path.Combine(directory, "2-jpg"));
Directory.CreateDirectory(Path.Combine(directory, "3-edit"));
string baseFilename = Path.GetFileName(Filename);
string rawFilename = Path.ChangeExtension(Filename, "cr3");
if (Path.Exists(rawFilename)) {
string rawOut = Path.Combine(directory, "1-raw", Path.GetFileName(rawFilename));
if (!Path.Exists(rawOut)) {
Console.WriteLine($"{rawFilename} => {rawOut}");
System.IO.File.Copy(rawFilename, rawOut);
}
}
// FIXME: add comments / captions as ImageDescription?
// FIXME: warn if the file already exists?
using (Image<Rgba32> image = await Image.LoadAsync<Rgba32>(Filename)) {
Util.RotateImageFromExif(image, Orientation);
if (CropRectangle != Rectangle.Empty) {
image.Mutate(x => x.Crop(CropRectangle));
}
ExifProfile exif = image.Metadata.ExifProfile ?? new();
exif.SetValue<ushort>(ExifTag.Orientation, 1);
@ -203,8 +214,16 @@ public class Photo {
image.Metadata.XmpProfile = UpdateXmp(image.Metadata.XmpProfile);
await image.SaveAsync(filename, encoder);
Console.WriteLine("saved " + filename);
string jpgOut = Path.Combine(directory, "2-jpg", baseFilename);
Console.WriteLine($"{Filename} => {jpgOut}");
await image.SaveAsync(jpgOut, encoder);
if (CropRectangle != Rectangle.Empty) {
image.Mutate(x => x.Crop(CropRectangle));
}
string editOut = Path.Combine(directory, "3-edit", baseFilename);
Console.WriteLine($"{Filename} => {editOut}");
await image.SaveAsync(editOut, encoder);
}
}

View File

@ -722,10 +722,10 @@ 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(@"c:\users\colin\pictures\photos\2023\07\23\");
// string[] files = Directory.GetFiles(@"c:\users\colin\pictures\photos\2023\09\06\jpg");
// string[] files = Directory.GetFiles(@"G:\DCIM\100EOSR6\");
// string[] files = Directory.GetFiles(@"c:\users\colin\desktop\totte-output\2023\08\29");
string[] files = Directory.GetFiles(@"c:\users\colin\desktop\import");
string[] files = Directory.GetFiles(@"c:\users\colin\desktop\export");
// 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\");