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:
@@ -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)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user