Browse Source

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.
pull/357/head
JimBobSquarePants 8 years ago
parent
commit
b19f655602
  1. 30
      src/ImageSharp/Processing/Processors/Transforms/RotateProcessor.cs

30
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
/// </summary>
private Matrix3x2 processMatrix;
/// <summary>
/// The final rotated angle.
/// </summary>
private int optimizedRotatedAngle;
/// <summary>
/// Gets or sets the angle of processMatrix in degrees.
/// </summary>
@ -87,6 +93,30 @@ namespace SixLabors.ImageSharp.Processing.Processors
}
}
/// <inheritdoc/>
protected override void AfterImageApply(Image<TPixel> 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);
}
}
/// <summary>
/// Rotates the images with an optimized method when the angle is 90, 180 or 270 degrees.
/// </summary>

Loading…
Cancel
Save