mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-04-03 17:56:44 +02:00
[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:
committed by
GitHub
parent
9d9df949ef
commit
9ca32aa3ea
@@ -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>
|
||||
|
||||
@@ -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()
|
||||
|
||||
BIN
src/modules/imageresizer/tests/TestMetadataIssue1928.jpg
Normal file
BIN
src/modules/imageresizer/tests/TestMetadataIssue1928.jpg
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 40 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 19 KiB |
Reference in New Issue
Block a user