|
|
@ -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); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|