[ImageResizer]Don't update metadata if image wasn't changed (#17880)

* Update ResizeOperation.cs

Add a new boolean to check if the image was resized, skip modifying the metadata if the image was not modified.

* Simplify code to prevent un-needed metadata work when the image isn't changed

Simplify code to prevent un-needed metadata work when the image isn't changed. Thanks Crutkas for the guidance.
This commit is contained in:
Adam Childers
2022-05-24 10:58:38 -04:00
committed by GitHub
parent 251ea6ded9
commit 61805aada2

View File

@@ -75,6 +75,14 @@ namespace ImageResizer.Models
foreach (var originalFrame in decoder.Frames) foreach (var originalFrame in decoder.Frames)
{ {
var transformedBitmap = Transform(originalFrame); var transformedBitmap = Transform(originalFrame);
// if the frame was not modified, we should not replace the metadata
if (transformedBitmap == originalFrame)
{
encoder.Frames.Add(originalFrame);
}
else
{
BitmapMetadata originalMetadata = (BitmapMetadata)originalFrame.Metadata; BitmapMetadata originalMetadata = (BitmapMetadata)originalFrame.Metadata;
#if DEBUG #if DEBUG
@@ -99,6 +107,7 @@ namespace ImageResizer.Models
encoder.Frames.Add(frame); encoder.Frames.Add(frame);
} }
}
path = GetDestinationPath(encoder); path = GetDestinationPath(encoder);
_fileSystem.Directory.CreateDirectory(_fileSystem.Path.GetDirectoryName(path)); _fileSystem.Directory.CreateDirectory(_fileSystem.Path.GetDirectoryName(path));