V12: Update ImageSharp V3 and Add Legacy V2 Project (#14216)

* Rename old imagesharp to v2

* Add Ronalds PR as imagesharp

* Ensure that we use V3 by default
This commit is contained in:
Mole
2023-05-09 10:09:54 +02:00
committed by GitHub
parent 7ca6cb97d3
commit 5e9ce916cf
16 changed files with 510 additions and 28 deletions

View File

@@ -1,4 +1,4 @@
using SixLabors.ImageSharp;
using SixLabors.ImageSharp.Formats;
using SixLabors.ImageSharp.Metadata.Profiles.Exif;
using Umbraco.Cms.Core.Media;
using Size = System.Drawing.Size;
@@ -28,31 +28,35 @@ public sealed class ImageSharpDimensionExtractor : IImageDimensionExtractor
{
Size? size = null;
IImageInfo imageInfo = Image.Identify(_configuration, stream);
if (imageInfo != null)
if (stream is not null)
{
size = IsExifOrientationRotated(imageInfo)
? new Size(imageInfo.Height, imageInfo.Width)
: new Size(imageInfo.Width, imageInfo.Height);
DecoderOptions options = new()
{
Configuration = _configuration,
};
ImageInfo imageInfo = Image.Identify(options, stream);
if (imageInfo != null)
{
size = IsExifOrientationRotated(imageInfo)
? new Size(imageInfo.Height, imageInfo.Width)
: new Size(imageInfo.Width, imageInfo.Height);
}
}
return size;
}
private static bool IsExifOrientationRotated(IImageInfo imageInfo)
private static bool IsExifOrientationRotated(ImageInfo imageInfo)
=> GetExifOrientation(imageInfo) switch
{
ExifOrientationMode.LeftTop
or ExifOrientationMode.RightTop
or ExifOrientationMode.RightBottom
or ExifOrientationMode.LeftBottom => true,
ExifOrientationMode.LeftTop or ExifOrientationMode.RightTop or ExifOrientationMode.RightBottom or ExifOrientationMode.LeftBottom => true,
_ => false,
};
private static ushort GetExifOrientation(IImageInfo imageInfo)
private static ushort GetExifOrientation(ImageInfo imageInfo)
{
IExifValue<ushort>? orientation = imageInfo.Metadata.ExifProfile?.GetValue(ExifTag.Orientation);
if (orientation is not null)
if (imageInfo.Metadata.ExifProfile?.TryGetValue(ExifTag.Orientation, out IExifValue<ushort>? orientation) == true)
{
if (orientation.DataType == ExifDataType.Short)
{