Remove EXIF orientation tag after image processing

Ensures EXIF orientation is cleared when cloning and after rotation,
preventing incorrect display in EXIF-aware viewers. Failures are
logged as debug messages without interrupting processing.
This commit is contained in:
MaddoScientisto 2026-02-21 14:12:15 +01:00
commit bbda970d57

View file

@ -113,6 +113,18 @@ public class ImageCreatorAlternate : IImageCreator
// Clone editable image so we don't mutate the original reference unexpectedly.
using var working = imgSharp.Clone();
// Ensure the EXIF orientation tag is not present on the working image so
// the final saved file has correct upright pixels and won't be
// re-oriented by EXIF-aware viewers.
try
{
working.Metadata?.ExifProfile?.RemoveValue(ExifTag.Orientation);
}
catch (Exception ex)
{
_logger?.LogDebug(ex, "[Alternate] Failed to clear EXIF orientation on working image");
}
// Ensure DataFoto is set (extracted earlier) so time-based text is available
imgState.DataFoto = imgState.CreationDate ?? DateTime.Now;
@ -500,6 +512,19 @@ public class ImageCreatorAlternate : IImageCreator
default:
break;
}
// After applying the pixel rotation, remove the EXIF orientation tag so
// viewers do not re-apply the rotation. Leaving the tag causes some
// viewers to display the image in the wrong (original) orientation.
try
{
img.Metadata?.ExifProfile?.RemoveValue(ExifTag.Orientation);
}
catch (Exception ex)
{
// Non-fatal: log and continue
_logger?.LogDebug(ex, "[Alternate] Could not clear EXIF orientation tag");
}
}
private System.Drawing.Size ComputeBigSize(int width, int height)