mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-04-10 21:41:51 +02:00
[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:
@@ -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));
|
||||||
|
|||||||
Reference in New Issue
Block a user