From 4f667f24002cc162b6c927193f375b6cd7aed098 Mon Sep 17 00:00:00 2001 From: Colin McMillen Date: Tue, 25 Jul 2023 14:48:02 -0400 Subject: [PATCH] handle all 8 Exif orientations --- Program.cs | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/Program.cs b/Program.cs index 36c7220..319157a 100644 --- a/Program.cs +++ b/Program.cs @@ -386,12 +386,20 @@ public static class Util { // https://sirv.com/help/articles/rotate-photos-to-be-upright/ public static void RotateImageFromExif(Image image, ushort orientation) { - if (orientation == 1) { + if (orientation <= 1) { return; } - if (orientation == 8) { - image.Mutate(x => x.RotateFlip(RotateMode.Rotate270, FlipMode.None)); - } + var operations = new Dictionary { + { 2, (RotateMode.None, FlipMode.Horizontal) }, + { 3, (RotateMode.Rotate180, FlipMode.None) }, + { 4, (RotateMode.Rotate180, FlipMode.Horizontal) }, + { 5, (RotateMode.Rotate90, FlipMode.Vertical) }, + { 6, (RotateMode.Rotate90, FlipMode.None) }, + { 7, (RotateMode.Rotate270, FlipMode.Vertical) }, + { 8, (RotateMode.Rotate270, FlipMode.None) }, + }; + var (rotate, flip) = operations[orientation]; + image.Mutate(x => x.RotateFlip(rotate, flip)); } public static Texture RenderText(string text) {