diff --git a/src/Umbraco.Cms.Imaging.ImageSharp/ConfigureImageSharpMiddlewareOptions.cs b/src/Umbraco.Cms.Imaging.ImageSharp/ConfigureImageSharpMiddlewareOptions.cs index 8daa1b689b01..aaaade354442 100644 --- a/src/Umbraco.Cms.Imaging.ImageSharp/ConfigureImageSharpMiddlewareOptions.cs +++ b/src/Umbraco.Cms.Imaging.ImageSharp/ConfigureImageSharpMiddlewareOptions.cs @@ -2,7 +2,6 @@ using Microsoft.AspNetCore.Http.Headers; using Microsoft.Extensions.Options; using Microsoft.Net.Http.Headers; -using SixLabors.ImageSharp; using SixLabors.ImageSharp.Web.Commands; using SixLabors.ImageSharp.Web.Middleware; using SixLabors.ImageSharp.Web.Processors; diff --git a/src/Umbraco.Cms.Imaging.ImageSharp/ImageProcessors/CropWebProcessor.cs b/src/Umbraco.Cms.Imaging.ImageSharp/ImageProcessors/CropWebProcessor.cs index eda49fa9d013..0107ae7d204d 100644 --- a/src/Umbraco.Cms.Imaging.ImageSharp/ImageProcessors/CropWebProcessor.cs +++ b/src/Umbraco.Cms.Imaging.ImageSharp/ImageProcessors/CropWebProcessor.cs @@ -1,10 +1,7 @@ using System.Globalization; using System.Numerics; using Microsoft.Extensions.Logging; -using SixLabors.ImageSharp; using SixLabors.ImageSharp.Metadata.Profiles.Exif; -using SixLabors.ImageSharp.Processing; -using SixLabors.ImageSharp.Web; using SixLabors.ImageSharp.Web.Commands; using SixLabors.ImageSharp.Web.Processors; @@ -48,7 +45,8 @@ public bool RequiresTrueColorPixelFormat(CommandCollection commands, CommandPars private static Rectangle? GetCropRectangle(FormattedImage image, CommandCollection commands, CommandParser parser, CultureInfo culture) { var coordinates = parser.ParseValue(commands.GetValueOrDefault(Coordinates), culture); - if (coordinates.Length != 4 || + if (coordinates is null || + coordinates.Length != 4 || (coordinates[0] == 0 && coordinates[1] == 0 && coordinates[2] == 0 && coordinates[3] == 0)) { return null; @@ -64,7 +62,7 @@ public bool RequiresTrueColorPixelFormat(CommandCollection commands, CommandPars Vector2 xy2 = ExifOrientationUtilities.Transform(new Vector2(right, bottom), Vector2.Zero, Vector2.One, orientation); // Scale points to a pixel based rectangle - Size size = image.Image.Size(); + Size size = image.Image.Size; return Rectangle.Round(RectangleF.FromLTRB( MathF.Min(xy1.X, xy2.X) * size.Width, diff --git a/src/Umbraco.Cms.Imaging.ImageSharp/ImageSharpComposer.cs b/src/Umbraco.Cms.Imaging.ImageSharp/ImageSharpComposer.cs index 9a77bc28b294..357a12556234 100644 --- a/src/Umbraco.Cms.Imaging.ImageSharp/ImageSharpComposer.cs +++ b/src/Umbraco.Cms.Imaging.ImageSharp/ImageSharpComposer.cs @@ -1,6 +1,5 @@ using Umbraco.Cms.Core.Composing; using Umbraco.Cms.Core.DependencyInjection; -using Umbraco.Extensions; namespace Umbraco.Cms.Imaging.ImageSharp; diff --git a/src/Umbraco.Cms.Imaging.ImageSharp/Media/ImageSharpDimensionExtractor.cs b/src/Umbraco.Cms.Imaging.ImageSharp/Media/ImageSharpDimensionExtractor.cs index 409b6e272663..0ec90bb358cc 100644 --- a/src/Umbraco.Cms.Imaging.ImageSharp/Media/ImageSharpDimensionExtractor.cs +++ b/src/Umbraco.Cms.Imaging.ImageSharp/Media/ImageSharpDimensionExtractor.cs @@ -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 ImageSharpDimensionExtractor(Configuration configuration) { 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? orientation = imageInfo.Metadata.ExifProfile?.GetValue(ExifTag.Orientation); - if (orientation is not null) + if (imageInfo.Metadata.ExifProfile?.TryGetValue(ExifTag.Orientation, out IExifValue? orientation) == true) { if (orientation.DataType == ExifDataType.Short) { diff --git a/src/Umbraco.Cms.Imaging.ImageSharp/Media/ImageSharpImageUrlGenerator.cs b/src/Umbraco.Cms.Imaging.ImageSharp/Media/ImageSharpImageUrlGenerator.cs index ad766031871e..d0f3b0d55a56 100644 --- a/src/Umbraco.Cms.Imaging.ImageSharp/Media/ImageSharpImageUrlGenerator.cs +++ b/src/Umbraco.Cms.Imaging.ImageSharp/Media/ImageSharpImageUrlGenerator.cs @@ -1,7 +1,6 @@ using System.Globalization; using Microsoft.AspNetCore.WebUtilities; using Microsoft.Extensions.Primitives; -using SixLabors.ImageSharp; using SixLabors.ImageSharp.Web.Processors; using Umbraco.Cms.Core.Media; using Umbraco.Cms.Core.Models; diff --git a/src/Umbraco.Cms.Imaging.ImageSharp/Umbraco.Cms.Imaging.ImageSharp.csproj b/src/Umbraco.Cms.Imaging.ImageSharp/Umbraco.Cms.Imaging.ImageSharp.csproj index 0eb87fbda776..e4eb1cd938a0 100644 --- a/src/Umbraco.Cms.Imaging.ImageSharp/Umbraco.Cms.Imaging.ImageSharp.csproj +++ b/src/Umbraco.Cms.Imaging.ImageSharp/Umbraco.Cms.Imaging.ImageSharp.csproj @@ -2,13 +2,12 @@ Umbraco CMS - Imaging - ImageSharp Adds imaging support using ImageSharp/ImageSharp.Web to Umbraco CMS. - - false + true - - + + diff --git a/src/Umbraco.Cms.Imaging.ImageSharp/UmbracoBuilderExtensions.cs b/src/Umbraco.Cms.Imaging.ImageSharp/UmbracoBuilderExtensions.cs index 4bd50034abd9..7af10cdefa21 100644 --- a/src/Umbraco.Cms.Imaging.ImageSharp/UmbracoBuilderExtensions.cs +++ b/src/Umbraco.Cms.Imaging.ImageSharp/UmbracoBuilderExtensions.cs @@ -1,6 +1,5 @@ using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Options; -using SixLabors.ImageSharp; using SixLabors.ImageSharp.Web.Caching; using SixLabors.ImageSharp.Web.DependencyInjection; using SixLabors.ImageSharp.Web.Middleware;