v11: Decouple dependencies (#12907)
* Move core dependencies and MSBuild targets from Umbraco.Cms to Umbraco.Cms.Targets * Re-add appsettings.Tests.json * Include appsettings-schema.json * Use .NET 7.x in CodeQL build * Fix duplicate Directory.Build.props import * Decouple ImageSharp/ImageSharp.Web implementations * Further decouple SqlServer implementation * Add SupportedImageFileTypes to IImageDimensionExtractor * Update descriptions * Update project metadata * Re-enable package validation * Add embedded package icon * Move ContinuousIntegrationBuild to build script * Move shared properties to root Directory.Build.props * Fix GetInstallState throwing exception when default provider isn't configured * Remove redundant PackageRequireLicenseAcceptance and update version to 11.0.0-rc1 * Update build script * Remove LangVersion preview * Disable app-local ICU for MacOS integration test * Disable app-local ICU for all integration tests * Fix RuntimeState_Run test assertion * Update projects and build script to require Node.js 16.17 (latest LTS) * Remove app-local ICU from unit tests * Add missing project reference * Generate XML documentation files * Expose management API in Web.UI project * Update .NET 7 dependencies to RC1 * Update package-lock.json files * Downgrade Cypress version
This commit is contained in:
@@ -0,0 +1,67 @@
|
||||
using SixLabors.ImageSharp;
|
||||
using SixLabors.ImageSharp.Metadata.Profiles.Exif;
|
||||
using Umbraco.Cms.Core.Media;
|
||||
using Size = System.Drawing.Size;
|
||||
|
||||
namespace Umbraco.Cms.Imaging.ImageSharp.Media;
|
||||
|
||||
public sealed class ImageSharpDimensionExtractor : IImageDimensionExtractor
|
||||
{
|
||||
private readonly Configuration _configuration;
|
||||
|
||||
/// <inheritdoc />
|
||||
public IEnumerable<string> SupportedImageFileTypes { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="ImageSharpDimensionExtractor" /> class.
|
||||
/// </summary>
|
||||
/// <param name="configuration">The configuration.</param>
|
||||
public ImageSharpDimensionExtractor(Configuration configuration)
|
||||
{
|
||||
_configuration = configuration ?? throw new ArgumentNullException(nameof(configuration));
|
||||
|
||||
SupportedImageFileTypes = configuration.ImageFormats.SelectMany(f => f.FileExtensions).ToArray();
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public Size? GetDimensions(Stream? stream)
|
||||
{
|
||||
Size? size = null;
|
||||
|
||||
IImageInfo imageInfo = Image.Identify(_configuration, 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)
|
||||
=> GetExifOrientation(imageInfo) switch
|
||||
{
|
||||
ExifOrientationMode.LeftTop
|
||||
or ExifOrientationMode.RightTop
|
||||
or ExifOrientationMode.RightBottom
|
||||
or ExifOrientationMode.LeftBottom => true,
|
||||
_ => false,
|
||||
};
|
||||
|
||||
private static ushort GetExifOrientation(IImageInfo imageInfo)
|
||||
{
|
||||
IExifValue<ushort>? orientation = imageInfo.Metadata.ExifProfile?.GetValue(ExifTag.Orientation);
|
||||
if (orientation is not null)
|
||||
{
|
||||
if (orientation.DataType == ExifDataType.Short)
|
||||
{
|
||||
return orientation.Value;
|
||||
}
|
||||
|
||||
return Convert.ToUInt16(orientation.Value);
|
||||
}
|
||||
|
||||
return ExifOrientationMode.Unknown;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user