|
| 1 | +// Copyright (c) Six Labors. |
| 2 | +// Licensed under the Apache License, Version 2.0. |
| 3 | + |
| 4 | +using System.Globalization; |
| 5 | +using SixLabors.ImageSharp.Formats.Png; |
| 6 | +using SixLabors.ImageSharp.Metadata.Profiles.Exif; |
| 7 | +using SixLabors.ImageSharp.PixelFormats; |
| 8 | +using SixLabors.ImageSharp.Web.Commands; |
| 9 | +using SixLabors.ImageSharp.Web.Commands.Converters; |
| 10 | +using SixLabors.ImageSharp.Web.Processors; |
| 11 | +using Xunit; |
| 12 | + |
| 13 | +namespace SixLabors.ImageSharp.Web.Tests.Processors |
| 14 | +{ |
| 15 | + public class AutoOrientWebProcessorTests |
| 16 | + { |
| 17 | + [Fact] |
| 18 | + public void AutoOrientWebProcessor_UpdatesOrientation() |
| 19 | + { |
| 20 | + CommandParser parser = new(new[] { new SimpleCommandConverter<bool>() }); |
| 21 | + CultureInfo culture = CultureInfo.InvariantCulture; |
| 22 | + |
| 23 | + CommandCollection commands = new() |
| 24 | + { |
| 25 | + { new(AutoOrientWebProcessor.AutoOrient, bool.TrueString) } |
| 26 | + }; |
| 27 | + |
| 28 | + const ushort tl = 1; |
| 29 | + const ushort br = 3; |
| 30 | + using var image = new Image<Rgba32>(1, 1); |
| 31 | + image.Metadata.ExifProfile = new(); |
| 32 | + image.Metadata.ExifProfile.SetValue(ExifTag.Orientation, br); |
| 33 | + |
| 34 | + IExifValue<ushort> orientation = image.Metadata.ExifProfile.GetValue(ExifTag.Orientation); |
| 35 | + Assert.Equal(br, orientation.Value); |
| 36 | + |
| 37 | + using var formatted = new FormattedImage(image, PngFormat.Instance); |
| 38 | + new AutoOrientWebProcessor().Process(formatted, null, commands, parser, culture); |
| 39 | + |
| 40 | + orientation = image.Metadata.ExifProfile.GetValue(ExifTag.Orientation); |
| 41 | + Assert.Equal(tl, orientation.Value); |
| 42 | + } |
| 43 | + } |
| 44 | +} |
0 commit comments