From 2e5416ba8d2414ca097afbab4775990f7bde7738 Mon Sep 17 00:00:00 2001 From: JimBobSquarePants Date: Thu, 5 Oct 2017 14:00:19 +1100 Subject: [PATCH 1/2] Update EXIF on rotate. Fix #268 Since we don't know the updated rotation value and EXIF tags only cover certain angles the best fix is to remove the rotate tag. We also update height width if the canvas has been expanded. --- .../Processors/Transforms/RotateProcessor.cs | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/src/ImageSharp/Processing/Processors/Transforms/RotateProcessor.cs b/src/ImageSharp/Processing/Processors/Transforms/RotateProcessor.cs index a7fb400ac..f057c8254 100644 --- a/src/ImageSharp/Processing/Processors/Transforms/RotateProcessor.cs +++ b/src/ImageSharp/Processing/Processors/Transforms/RotateProcessor.cs @@ -7,6 +7,7 @@ using System.Threading.Tasks; using SixLabors.ImageSharp.Advanced; using SixLabors.ImageSharp.Helpers; using SixLabors.ImageSharp.Memory; +using SixLabors.ImageSharp.MetaData.Profiles.Exif; using SixLabors.ImageSharp.PixelFormats; using SixLabors.Primitives; @@ -24,6 +25,11 @@ namespace SixLabors.ImageSharp.Processing.Processors /// private Matrix3x2 processMatrix; + /// + /// The final rotated angle. + /// + private int optimizedRotatedAngle; + /// /// Gets or sets the angle of processMatrix in degrees. /// @@ -87,6 +93,30 @@ namespace SixLabors.ImageSharp.Processing.Processors } } + /// + protected override void AfterImageApply(Image source, Rectangle sourceRectangle) + { + ExifProfile profile = source.MetaData.ExifProfile; + if (profile == null) + { + return; + } + + if (MathF.Abs(this.Angle) < Constants.Epsilon) + { + // No need to do anything so return. + return; + } + + profile.RemoveValue(ExifTag.Orientation); + + if (this.Expand && profile.GetValue(ExifTag.PixelXDimension) != null) + { + profile.SetValue(ExifTag.PixelXDimension, source.Width); + profile.SetValue(ExifTag.PixelYDimension, source.Height); + } + } + /// /// Rotates the images with an optimized method when the angle is 90, 180 or 270 degrees. /// From ff774968f361670179a78e48be2eaa7834b8070b Mon Sep 17 00:00:00 2001 From: JimBobSquarePants Date: Thu, 5 Oct 2017 14:03:27 +1100 Subject: [PATCH 2/2] Remove unused field --- .../Processing/Processors/Transforms/RotateProcessor.cs | 5 ----- 1 file changed, 5 deletions(-) diff --git a/src/ImageSharp/Processing/Processors/Transforms/RotateProcessor.cs b/src/ImageSharp/Processing/Processors/Transforms/RotateProcessor.cs index f057c8254..86a0c7360 100644 --- a/src/ImageSharp/Processing/Processors/Transforms/RotateProcessor.cs +++ b/src/ImageSharp/Processing/Processors/Transforms/RotateProcessor.cs @@ -25,11 +25,6 @@ namespace SixLabors.ImageSharp.Processing.Processors /// private Matrix3x2 processMatrix; - /// - /// The final rotated angle. - /// - private int optimizedRotatedAngle; - /// /// Gets or sets the angle of processMatrix in degrees. ///