feat: Add EXIF data removal option and update related UI bindings
Some checks failed
Build Windows Avalonia / build (push) Failing after 2m32s

This commit is contained in:
Maddo 2026-11-30 19:18:08 +01:00
commit fc0598e2fb
10 changed files with 104 additions and 72 deletions

View file

@ -1,6 +1,9 @@
using System.IO;
using System.Threading.Tasks;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using SixLabors.ImageSharp;
using SixLabors.ImageSharp.Formats.Jpeg;
using SixLabors.ImageSharp.Metadata.Profiles.Exif;
using SixLabors.ImageSharp.PixelFormats;
using MaddoShared.ImageSharpTests.Helpers;
using Shouldly;
@ -40,5 +43,57 @@ namespace MaddoShared.ImageSharpTests.Tests
outImg.Width.ShouldBe(800);
outImg.Height.ShouldBe(600);
}
[TestMethod]
public async Task RemoveExifData_StripsExifProfileWhenEnabledAndPreservesItWhenDisabled()
{
using var ws = new TempWorkspace();
var preserveInputPath = CreateJpegWithExifMake(ws.SourceDir.FullName, "preserve.jpg");
var stripInputPath = CreateJpegWithExifMake(ws.SourceDir.FullName, "strip.jpg");
var preserveSettings = CreatorFactory.CreateDefaultPicSettings();
preserveSettings.RemoveExifData = false;
var preserveCreator = CreatorFactory.CreateImageCreator(preserveSettings);
var preserveState = new MaddoShared.ImageState
{
WorkFile = new FileInfo(preserveInputPath),
DestDir = ws.DestDir
};
await preserveCreator.CreateImageAsync(preserveState, null);
var stripSettings = CreatorFactory.CreateDefaultPicSettings();
stripSettings.RemoveExifData = true;
stripSettings.CreaMiniature = true;
var stripCreator = CreatorFactory.CreateImageCreator(stripSettings);
var stripState = new MaddoShared.ImageState
{
WorkFile = new FileInfo(stripInputPath),
DestDir = ws.DestDir
};
await stripCreator.CreateImageAsync(stripState, null);
using var preservedOutput = Image.Load<Rgba32>(Path.Combine(ws.DestDir.FullName, preserveState.NomeFileBig));
var preservedExif = preservedOutput.Metadata.ExifProfile;
preservedExif.ShouldNotBeNull();
preservedExif.TryGetValue(ExifTag.Make, out var make).ShouldBeTrue();
make!.Value.ShouldBe("Test camera");
using var strippedOutput = Image.Load<Rgba32>(Path.Combine(ws.DestDir.FullName, stripState.NomeFileBig));
strippedOutput.Metadata.ExifProfile.ShouldBeNull();
using var strippedThumbnail = Image.Load<Rgba32>(Path.Combine(ws.DestDir.FullName, stripState.NomeFileSmall));
strippedThumbnail.Metadata.ExifProfile.ShouldBeNull();
}
private static string CreateJpegWithExifMake(string directory, string fileName)
{
var path = TestImageFactory.CreateSolidJpeg(directory, fileName, 160, 120, new Rgba32(200, 200, 200, 255));
using var image = Image.Load<Rgba32>(path);
var exifProfile = new ExifProfile();
exifProfile.SetValue(ExifTag.Make, "Test camera");
image.Metadata.ExifProfile = exifProfile;
image.Save(path, new JpegEncoder { Quality = 90 });
return path;
}
}
}