diff --git a/MaddoShared/ImageCreatorAlternate.cs b/MaddoShared/ImageCreatorAlternate.cs index 80f42d3..ddb9690 100644 --- a/MaddoShared/ImageCreatorAlternate.cs +++ b/MaddoShared/ImageCreatorAlternate.cs @@ -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)