[Image Resizer] Add option to remove metadata (#14176)

* Implements option to remove metadata (see #1928)

* Add unit test

* renamed settings switch, update ui text

* Fix exception type, add justification for swallowing exception

* Add unit test to check handling if no metadata is there in targetfile

* Reordered the checkboxes as suggested by @htcfreek

* Reduced size of test image
This commit is contained in:
CleanCodeDeveloper
2021-11-03 19:05:35 +01:00
committed by GitHub
parent 9d9df949ef
commit 9ca32aa3ea
10 changed files with 166 additions and 4 deletions

View File

@@ -28,6 +28,10 @@
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<PlatformTarget>x64</PlatformTarget>
</PropertyGroup>
<ItemGroup>
<None Remove="TestMetadataIssue1928.jpg" />
<None Remove="TestMetadataIssue1928_NoMetadata.jpg" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\ui\ImageResizerUI.csproj" />
@@ -53,6 +57,12 @@
<Content Include="Test.png">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="TestMetadataIssue1928.jpg">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="TestMetadataIssue1928_NoMetadata.jpg">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="TestMetadataIssue2447.jpg">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>

View File

@@ -7,6 +7,7 @@ using System.IO;
using System.Linq;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using ImageResizer.Extensions;
using ImageResizer.Properties;
using ImageResizer.Test;
using Microsoft.VisualStudio.TestTools.UnitTesting;
@@ -441,6 +442,50 @@ namespace ImageResizer.Models
Assert.IsTrue(File.Exists(_directory + @"\Directory\Test (Test).png"));
}
[TestMethod]
public void StripMetadata()
{
var operation = new ResizeOperation(
"TestMetadataIssue1928.jpg",
_directory,
Settings(
x =>
{
x.RemoveMetadata = true;
}));
operation.Execute();
AssertEx.Image(
_directory.File(),
image => Assert.IsNull(((BitmapMetadata)image.Frames[0].Metadata).DateTaken));
AssertEx.Image(
_directory.File(),
image => Assert.IsNotNull(((BitmapMetadata)image.Frames[0].Metadata).GetQuerySafe("System.Photo.Orientation")));
}
[TestMethod]
public void StripMetadataWhenNoMetadataPresent()
{
var operation = new ResizeOperation(
"TestMetadataIssue1928_NoMetadata.jpg",
_directory,
Settings(
x =>
{
x.RemoveMetadata = true;
}));
operation.Execute();
AssertEx.Image(
_directory.File(),
image => Assert.IsNull(((BitmapMetadata)image.Frames[0].Metadata).DateTaken));
AssertEx.Image(
_directory.File(),
image => Assert.IsNull(((BitmapMetadata)image.Frames[0].Metadata).GetQuerySafe("System.Photo.Orientation")));
}
private static Settings Settings(Action<Settings> action = null)
{
var settings = new Settings()

Binary file not shown.

After

Width:  |  Height:  |  Size: 40 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 19 KiB