[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

@@ -10,6 +10,7 @@ using System.Linq;
using System.Windows;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using ImageResizer.Extensions;
using ImageResizer.Properties;
using ImageResizer.Utilities;
using Microsoft.VisualBasic.FileIO;
@@ -82,11 +83,22 @@ namespace ImageResizer.Models
}
}
if (_settings.RemoveMetadata && metadata != null)
{
// strip any metadata that doesn't affect rendering
var newMetadata = new BitmapMetadata(metadata.Format);
metadata.CopyMetadataPropertyTo(newMetadata, "System.Photo.Orientation");
metadata.CopyMetadataPropertyTo(newMetadata, "System.Image.ColorSpace");
metadata = newMetadata;
}
encoder.Frames.Add(
BitmapFrame.Create(
Transform(originalFrame),
thumbnail: null,
metadata, // TODO: Add an option to strip any metadata that doesn't affect rendering (issue #3)
metadata,
colorContexts: null));
}