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:
Ronald Barendse
2022-09-27 14:22:34 +02:00
committed by GitHub
parent d206df0cac
commit 3873a0735c
90 changed files with 1061 additions and 1350 deletions

View File

@@ -0,0 +1,87 @@
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;
namespace Umbraco.Cms.Imaging.ImageSharp.ImageProcessors;
/// <summary>
/// Allows the cropping of images.
/// </summary>
/// <seealso cref="SixLabors.ImageSharp.Web.Processors.IImageWebProcessor" />
public class CropWebProcessor : IImageWebProcessor
{
/// <summary>
/// The command constant for the crop coordinates.
/// </summary>
public const string Coordinates = "cc";
/// <summary>
/// The command constant for the resize orientation handling mode.
/// </summary>
public const string Orient = "orient";
/// <inheritdoc />
public IEnumerable<string> Commands { get; } = new[] { Coordinates, Orient };
/// <inheritdoc />
public FormattedImage Process(FormattedImage image, ILogger logger, CommandCollection commands, CommandParser parser, CultureInfo culture)
{
Rectangle? cropRectangle = GetCropRectangle(image, commands, parser, culture);
if (cropRectangle.HasValue)
{
image.Image.Mutate(x => x.Crop(cropRectangle.Value));
}
return image;
}
/// <inheritdoc />
public bool RequiresTrueColorPixelFormat(CommandCollection commands, CommandParser parser, CultureInfo culture) =>
false;
private static Rectangle? GetCropRectangle(FormattedImage image, CommandCollection commands, CommandParser parser, CultureInfo culture)
{
var coordinates = parser.ParseValue<float[]>(commands.GetValueOrDefault(Coordinates), culture);
if (coordinates.Length != 4 ||
(coordinates[0] == 0 && coordinates[1] == 0 && coordinates[2] == 0 && coordinates[3] == 0))
{
return null;
}
// The right and bottom values are actually the distance from those sides, so convert them into real coordinates and transform to correct orientation
var left = Math.Clamp(coordinates[0], 0, 1);
var top = Math.Clamp(coordinates[1], 0, 1);
var right = Math.Clamp(1 - coordinates[2], 0, 1);
var bottom = Math.Clamp(1 - coordinates[3], 0, 1);
var orientation = GetExifOrientation(image, commands, parser, culture);
Vector2 xy1 = ExifOrientationUtilities.Transform(new Vector2(left, top), Vector2.Zero, Vector2.One, orientation);
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();
return Rectangle.Round(RectangleF.FromLTRB(
MathF.Min(xy1.X, xy2.X) * size.Width,
MathF.Min(xy1.Y, xy2.Y) * size.Height,
MathF.Max(xy1.X, xy2.X) * size.Width,
MathF.Max(xy1.Y, xy2.Y) * size.Height));
}
private static ushort GetExifOrientation(FormattedImage image, CommandCollection commands, CommandParser parser, CultureInfo culture)
{
if (commands.Contains(Orient) && !parser.ParseValue<bool>(commands.GetValueOrDefault(Orient), culture))
{
return ExifOrientationMode.Unknown;
}
image.TryGetExifOrientation(out var orientation);
return orientation;
}
}