diff --git a/src/Umbraco.Infrastructure/PropertyEditors/ValueConverters/ImageCropperValue.cs b/src/Umbraco.Infrastructure/PropertyEditors/ValueConverters/ImageCropperValue.cs index 32101d6cf7..09e080e0b0 100644 --- a/src/Umbraco.Infrastructure/PropertyEditors/ValueConverters/ImageCropperValue.cs +++ b/src/Umbraco.Infrastructure/PropertyEditors/ValueConverters/ImageCropperValue.cs @@ -1,4 +1,4 @@ -// Copyright (c) Umbraco. +// Copyright (c) Umbraco. // See LICENSE for more details. using System; @@ -77,7 +77,7 @@ namespace Umbraco.Cms.Core.PropertyEditors.ValueConverters } else { - return new ImageUrlGenerationOptions(url) { DefaultCrop = true }; + return new ImageUrlGenerationOptions(url); } } diff --git a/src/Umbraco.Web.BackOffice/Controllers/BackOfficeServerVariables.cs b/src/Umbraco.Web.BackOffice/Controllers/BackOfficeServerVariables.cs index c3fb203ec1..c822b61d67 100644 --- a/src/Umbraco.Web.BackOffice/Controllers/BackOfficeServerVariables.cs +++ b/src/Umbraco.Web.BackOffice/Controllers/BackOfficeServerVariables.cs @@ -365,7 +365,7 @@ namespace Umbraco.Cms.Web.BackOffice.Controllers }, { "imageUrlGeneratorApiBaseUrl", _linkGenerator.GetUmbracoApiServiceBaseUrl( - controller => controller.GetCropUrl(null, null, null, null, null)) + controller => controller.GetCropUrl(null, null, null, null)) }, { "elementTypeApiBaseUrl", _linkGenerator.GetUmbracoApiServiceBaseUrl( diff --git a/src/Umbraco.Web.BackOffice/Controllers/ImageUrlGeneratorController.cs b/src/Umbraco.Web.BackOffice/Controllers/ImageUrlGeneratorController.cs index 1d72c80ad8..7546fdf38d 100644 --- a/src/Umbraco.Web.BackOffice/Controllers/ImageUrlGeneratorController.cs +++ b/src/Umbraco.Web.BackOffice/Controllers/ImageUrlGeneratorController.cs @@ -1,4 +1,4 @@ -using Umbraco.Cms.Core.Media; +using Umbraco.Cms.Core.Media; using Umbraco.Cms.Core.Models; using Umbraco.Cms.Web.Common.Attributes; using Constants = Umbraco.Cms.Core.Constants; @@ -21,20 +21,13 @@ namespace Umbraco.Cms.Web.BackOffice.Controllers { private readonly IImageUrlGenerator _imageUrlGenerator; - public ImageUrlGeneratorController(IImageUrlGenerator imageUrlGenerator) - { - _imageUrlGenerator = imageUrlGenerator; - } + public ImageUrlGeneratorController(IImageUrlGenerator imageUrlGenerator) => _imageUrlGenerator = imageUrlGenerator; - public string GetCropUrl(string mediaPath, int? width = null, int? height = null, ImageCropMode? imageCropMode = null, string animationProcessMode = null) + public string GetCropUrl(string mediaPath, int? width = null, int? height = null, ImageCropMode? imageCropMode = null) => _imageUrlGenerator.GetImageUrl(new ImageUrlGenerationOptions(mediaPath) { - return _imageUrlGenerator.GetImageUrl(new ImageUrlGenerationOptions(mediaPath) - { - Width = width, - Height = height, - ImageCropMode = imageCropMode, - AnimationProcessMode = animationProcessMode - }); - } + Width = width, + Height = height, + ImageCropMode = imageCropMode + }); } } diff --git a/src/Umbraco.Web.BackOffice/Controllers/ImagesController.cs b/src/Umbraco.Web.BackOffice/Controllers/ImagesController.cs index 24135bcbe6..00a18ec8b7 100644 --- a/src/Umbraco.Web.BackOffice/Controllers/ImagesController.cs +++ b/src/Umbraco.Web.BackOffice/Controllers/ImagesController.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.IO; using Microsoft.AspNetCore.Mvc; using Umbraco.Cms.Core.IO; @@ -76,9 +76,7 @@ namespace Umbraco.Cms.Web.BackOffice.Controllers var rnd = imageLastModified.HasValue ? $"&rnd={imageLastModified:yyyyMMddHHmmss}" : null; var imageUrl = _imageUrlGenerator.GetImageUrl(new ImageUrlGenerationOptions(imagePath) { - UpScale = false, Width = width, - AnimationProcessMode = "first", ImageCropMode = ImageCropMode.Max, CacheBusterValue = rnd }); @@ -94,9 +92,7 @@ namespace Umbraco.Cms.Web.BackOffice.Controllers /// /// /// - /// /// - /// /// /// /// If there is no media, image property or image file is found then this will return not found. @@ -106,9 +102,7 @@ namespace Umbraco.Cms.Web.BackOffice.Controllers int? height = null, decimal? focalPointLeft = null, decimal? focalPointTop = null, - string animationProcessMode = "first", ImageCropMode mode = ImageCropMode.Max, - bool upscale = false, string cacheBusterValue = "", decimal? cropX1 = null, decimal? cropX2 = null, @@ -116,45 +110,24 @@ namespace Umbraco.Cms.Web.BackOffice.Controllers decimal? cropY2 = null ) { - - var options = new ImageUrlGenerationOptions(imagePath) { - AnimationProcessMode = animationProcessMode, - CacheBusterValue = cacheBusterValue, + Width = width, Height = height, ImageCropMode = mode, - UpScale = upscale, - Width = width, - Crop = (cropX1.HasValue && cropX2.HasValue && cropY1.HasValue && cropY2.HasValue) ? new ImageUrlGenerationOptions.CropCoordinates(cropX1.Value, cropY1.Value, cropX2.Value, cropY2.Value) : null, - FocalPoint = new ImageUrlGenerationOptions.FocalPointPosition(focalPointTop.GetValueOrDefault(0.5m), focalPointLeft.GetValueOrDefault(0.5m)), + CacheBusterValue = cacheBusterValue }; + if (focalPointLeft.HasValue && focalPointTop.HasValue) { - options.FocalPoint = - new ImageUrlGenerationOptions.FocalPointPosition(focalPointTop.Value, focalPointLeft.Value); + options.FocalPoint = new ImageUrlGenerationOptions.FocalPointPosition(focalPointTop.Value, focalPointLeft.Value); + } + else if (cropX1.HasValue && cropX2.HasValue && cropY1.HasValue && cropY2.HasValue) + { + options.Crop = new ImageUrlGenerationOptions.CropCoordinates(cropX1.Value, cropY1.Value, cropX2.Value, cropY2.Value); } return _imageUrlGenerator.GetImageUrl(options); } - - public class FocalPointPositionModel - { - public decimal Left { get; set; } - public decimal Top { get; set; } - } - - /// - /// The bounds of the crop within the original image, in whatever units the registered - /// IImageUrlGenerator uses, typically a percentage between 0 and 100. - /// - public class CropCoordinatesModel - { - - public decimal X1 { get; set; } - public decimal Y1 { get; set; } - public decimal X2 { get; set;} - public decimal Y2 { get; set;} - } } } diff --git a/src/Umbraco.Web.Common/Extensions/FriendlyImageCropperTemplateExtensions.cs b/src/Umbraco.Web.Common/Extensions/FriendlyImageCropperTemplateExtensions.cs index 94e24a5027..19090ee12e 100644 --- a/src/Umbraco.Web.Common/Extensions/FriendlyImageCropperTemplateExtensions.cs +++ b/src/Umbraco.Web.Common/Extensions/FriendlyImageCropperTemplateExtensions.cs @@ -1,4 +1,4 @@ -using System; +using System; using Microsoft.Extensions.DependencyInjection; using Umbraco.Cms.Core.Media; using Umbraco.Cms.Core.Models; @@ -11,25 +11,17 @@ namespace Umbraco.Extensions { public static class FriendlyImageCropperTemplateExtensions { - private static IImageUrlGenerator ImageUrlGenerator { get; } = - StaticServiceProvider.Instance.GetRequiredService(); + private static IImageUrlGenerator ImageUrlGenerator { get; } = StaticServiceProvider.Instance.GetRequiredService(); - private static IPublishedValueFallback PublishedValueFallback { get; } = - StaticServiceProvider.Instance.GetRequiredService(); - - private static IPublishedUrlProvider PublishedUrlProvider { get; } = - StaticServiceProvider.Instance.GetRequiredService(); + private static IPublishedValueFallback PublishedValueFallback { get; } = StaticServiceProvider.Instance.GetRequiredService(); + private static IPublishedUrlProvider PublishedUrlProvider { get; } = StaticServiceProvider.Instance.GetRequiredService(); /// - /// Gets the underlying image processing service URL by the crop alias (from the "umbracoFile" property alias) on the IPublishedContent item + /// Gets the underlying image processing service URL by the crop alias (from the "umbracoFile" property alias) on the IPublishedContent item. /// - /// - /// The IPublishedContent item. - /// - /// - /// The crop alias e.g. thumbnail - /// + /// The IPublishedContent item. + /// The crop alias e.g. thumbnail. /// /// The URL of the cropped image. /// @@ -57,17 +49,11 @@ namespace Umbraco.Extensions => ImageCropperTemplateCoreExtensions.GetCropUrl(mediaItem, imageCropperValue, cropAlias, ImageUrlGenerator, PublishedValueFallback, PublishedUrlProvider); /// - /// Gets the underlying image processing service URL by the crop alias using the specified property containing the image cropper Json data on the IPublishedContent item. + /// Gets the underlying image processing service URL by the crop alias using the specified property containing the image cropper JSON data on the IPublishedContent item. /// - /// - /// The IPublishedContent item. - /// - /// - /// The property alias of the property containing the Json data e.g. umbracoFile - /// - /// - /// The crop alias e.g. thumbnail - /// + /// The IPublishedContent item. + /// The property alias of the property containing the JSON data e.g. umbracoFile. + /// The crop alias e.g. thumbnail. /// /// The URL of the cropped image. /// @@ -83,53 +69,22 @@ namespace Umbraco.Extensions /// /// Gets the underlying image processing service URL from the IPublishedContent item. /// - /// - /// The IPublishedContent item. - /// - /// - /// The width of the output image. - /// - /// - /// The height of the output image. - /// - /// - /// Property alias of the property containing the Json data. - /// - /// - /// The crop alias. - /// - /// - /// Quality percentage of the output image. - /// - /// - /// The image crop mode. - /// - /// - /// The image crop anchor. - /// - /// - /// Use focal point, to generate an output image using the focal point instead of the predefined crop - /// - /// - /// Use crop dimensions to have the output image sized according to the predefined crop sizes, this will override the width and height parameters. - /// - /// - /// Add a serialized date of the last edit of the item to ensure client cache refresh when updated - /// - /// - /// These are any query string parameters (formatted as query strings) that the underlying image processing service supports. For example: - /// - /// The IPublishedContent item. + /// The width of the output image. + /// The height of the output image. + /// Property alias of the property containing the JSON data. + /// The crop alias. + /// Quality percentage of the output image. + /// The image crop mode. + /// The image crop anchor. + /// Use focal point, to generate an output image using the focal point instead of the predefined crop. + /// Use crop dimensions to have the output image sized according to the predefined crop sizes, this will override the width and height parameters. + /// Add a serialized date of the last edit of the item to ensure client cache refresh when updated. + /// These are any query string parameters (formatted as query strings) that the underlying image processing service supports. For example: + /// - /// - /// - /// - /// Use a dimension as a ratio - /// - /// - /// If the image should be upscaled to requested dimensions - /// + /// ]]> + /// Use a dimension as a ratio. /// /// The URL of the cropped image. /// @@ -146,8 +101,7 @@ namespace Umbraco.Extensions bool useCropDimensions = false, bool cacheBuster = true, string furtherOptions = null, - ImageCropRatioMode? ratioMode = null, - bool upScale = true) + ImageCropRatioMode? ratioMode = null) => mediaItem.GetCropUrl( ImageUrlGenerator, PublishedValueFallback, @@ -163,62 +117,30 @@ namespace Umbraco.Extensions useCropDimensions, cacheBuster, furtherOptions, - ratioMode, - upScale + ratioMode ); /// /// Gets the underlying image processing service URL from the image path. /// - /// - /// The image URL. - /// - /// - /// The width of the output image. - /// - /// - /// The height of the output image. - /// - /// - /// The Json data from the Umbraco Core Image Cropper property editor - /// - /// - /// The crop alias. - /// - /// - /// Quality percentage of the output image. - /// - /// - /// The image crop mode. - /// - /// - /// The image crop anchor. - /// - /// - /// Use focal point to generate an output image using the focal point instead of the predefined crop if there is one - /// - /// - /// Use crop dimensions to have the output image sized according to the predefined crop sizes, this will override the width and height parameters - /// - /// - /// Add a serialized date of the last edit of the item to ensure client cache refresh when updated - /// - /// - /// These are any query string parameters (formatted as query strings) that the underlying image processing service supports. For example: - /// - /// The image URL. + /// The width of the output image. + /// The height of the output image. + /// The JSON data from the Umbraco Core Image Cropper property editor. + /// The crop alias. + /// Quality percentage of the output image. + /// The image crop mode. + /// The image crop anchor. + /// Use focal point to generate an output image using the focal point instead of the predefined crop if there is one. + /// Use crop dimensions to have the output image sized according to the predefined crop sizes, this will override the width and height parameters. + /// Add a serialized date of the last edit of the item to ensure client cache refresh when updated. + /// These are any query string parameters (formatted as query strings) that the underlying image processing service supports. For example: + /// - /// - /// - /// - /// Use a dimension as a ratio - /// - /// - /// If the image should be upscaled to requested dimensions - /// + /// ]]> + /// Use a dimension as a ratio. /// - /// The the URL of the cropped image. + /// The URL of the cropped image. /// public static string GetCropUrl( this string imageUrl, @@ -233,8 +155,7 @@ namespace Umbraco.Extensions bool useCropDimensions = false, string cacheBusterValue = null, string furtherOptions = null, - ImageCropRatioMode? ratioMode = null, - bool upScale = true) + ImageCropRatioMode? ratioMode = null) => imageUrl.GetCropUrl( ImageUrlGenerator, width, @@ -248,60 +169,30 @@ namespace Umbraco.Extensions useCropDimensions, cacheBusterValue, furtherOptions, - ratioMode, - upScale - ); + ratioMode + ); /// /// Gets the underlying image processing service URL from the image path. /// - /// - /// The image URL. - /// - /// - /// - /// The width of the output image. - /// - /// - /// The height of the output image. - /// - /// - /// The crop alias. - /// - /// - /// Quality percentage of the output image. - /// - /// - /// The image crop mode. - /// - /// - /// The image crop anchor. - /// - /// - /// Use focal point to generate an output image using the focal point instead of the predefined crop if there is one - /// - /// - /// Use crop dimensions to have the output image sized according to the predefined crop sizes, this will override the width and height parameters - /// - /// - /// Add a serialized date of the last edit of the item to ensure client cache refresh when updated - /// - /// - /// These are any query string parameters (formatted as query strings) that the underlying image processing service supports. For example: - /// - /// The image URL. + /// The crop data set. + /// The width of the output image. + /// The height of the output image. + /// The crop alias. + /// Quality percentage of the output image. + /// The image crop mode. + /// The image crop anchor. + /// Use focal point to generate an output image using the focal point instead of the predefined crop if there is one. + /// Use crop dimensions to have the output image sized according to the predefined crop sizes, this will override the width and height parameters. + /// Add a serialized date of the last edit of the item to ensure client cache refresh when updated. + /// These are any query string parameters (formatted as query strings) that the underlying image processing service supports. For example: + /// - /// - /// - /// - /// Use a dimension as a ratio - /// - /// - /// If the image should be upscaled to requested dimensions - /// + /// ]]> + /// Use a dimension as a ratio /// - /// The the URL of the cropped image. + /// The URL of the cropped image. /// public static string GetCropUrl( this string imageUrl, @@ -316,9 +207,7 @@ namespace Umbraco.Extensions bool useCropDimensions = false, string cacheBusterValue = null, string furtherOptions = null, - ImageCropRatioMode? ratioMode = null, - bool upScale = true, - string animationProcessMode = null) + ImageCropRatioMode? ratioMode = null) => imageUrl.GetCropUrl( ImageUrlGenerator, cropDataSet, @@ -331,9 +220,7 @@ namespace Umbraco.Extensions useCropDimensions, cacheBusterValue, furtherOptions, - ratioMode, - upScale, - animationProcessMode + ratioMode ); @@ -341,10 +228,6 @@ namespace Umbraco.Extensions public static string GetLocalCropUrl( this MediaWithCrops mediaWithCrops, string alias, - string cacheBusterValue = null) - { - return mediaWithCrops.LocalCrops.Src + - mediaWithCrops.LocalCrops.GetCropUrl(alias, ImageUrlGenerator, cacheBusterValue: cacheBusterValue); - } + string cacheBusterValue = null) => mediaWithCrops.LocalCrops.Src + mediaWithCrops.LocalCrops.GetCropUrl(alias, ImageUrlGenerator, cacheBusterValue: cacheBusterValue); } } diff --git a/src/Umbraco.Web.Common/Extensions/ImageCropperTemplateCoreExtensions.cs b/src/Umbraco.Web.Common/Extensions/ImageCropperTemplateCoreExtensions.cs index 27de0d22b2..00d4dcdb77 100644 --- a/src/Umbraco.Web.Common/Extensions/ImageCropperTemplateCoreExtensions.cs +++ b/src/Umbraco.Web.Common/Extensions/ImageCropperTemplateCoreExtensions.cs @@ -13,17 +13,13 @@ namespace Umbraco.Extensions public static class ImageCropperTemplateCoreExtensions { /// - /// Gets the underlying image processing service URL by the crop alias (from the "umbracoFile" property alias) on the IPublishedContent item + /// Gets the underlying image processing service URL by the crop alias (from the "umbracoFile" property alias) on the IPublishedContent item. /// - /// - /// The IPublishedContent item. - /// - /// - /// The crop alias e.g. thumbnail - /// - /// The image url generator. + /// The IPublishedContent item. + /// The crop alias e.g. thumbnail. + /// The image URL generator. /// The published value fallback. - /// The published url provider. + /// The published URL provider. /// /// The URL of the cropped image. /// @@ -32,20 +28,14 @@ namespace Umbraco.Extensions string cropAlias, IImageUrlGenerator imageUrlGenerator, IPublishedValueFallback publishedValueFallback, - IPublishedUrlProvider publishedUrlProvider) - { - return mediaItem.GetCropUrl(imageUrlGenerator, publishedValueFallback, publishedUrlProvider, cropAlias: cropAlias, useCropDimensions: true); - } + IPublishedUrlProvider publishedUrlProvider) => mediaItem.GetCropUrl(imageUrlGenerator, publishedValueFallback, publishedUrlProvider, cropAlias: cropAlias, useCropDimensions: true); public static string GetCropUrl( this MediaWithCrops mediaWithCrops, string cropAlias, IImageUrlGenerator imageUrlGenerator, IPublishedValueFallback publishedValueFallback, - IPublishedUrlProvider publishedUrlProvider) - { - return mediaWithCrops.GetCropUrl(imageUrlGenerator, publishedValueFallback, publishedUrlProvider, cropAlias: cropAlias, useCropDimensions: true); - } + IPublishedUrlProvider publishedUrlProvider) => mediaWithCrops.GetCropUrl(imageUrlGenerator, publishedValueFallback, publishedUrlProvider, cropAlias: cropAlias, useCropDimensions: true); /// /// Gets the crop URL by using only the specified . @@ -54,6 +44,8 @@ namespace Umbraco.Extensions /// The image cropper value. /// The crop alias. /// The image URL generator. + /// The published value fallback. + /// The published URL provider. /// /// The image crop URL. /// @@ -63,26 +55,17 @@ namespace Umbraco.Extensions string cropAlias, IImageUrlGenerator imageUrlGenerator, IPublishedValueFallback publishedValueFallback, - IPublishedUrlProvider publishedUrlProvider) - { - return mediaItem.GetCropUrl(imageUrlGenerator, publishedValueFallback, publishedUrlProvider, imageCropperValue, true, cropAlias: cropAlias, useCropDimensions: true); - } + IPublishedUrlProvider publishedUrlProvider) => mediaItem.GetCropUrl(imageUrlGenerator, publishedValueFallback, publishedUrlProvider, imageCropperValue, true, cropAlias: cropAlias, useCropDimensions: true); /// - /// Gets the underlying image processing service URL by the crop alias using the specified property containing the image cropper Json data on the IPublishedContent item. + /// Gets the underlying image processing service URL by the crop alias using the specified property containing the image cropper JSON data on the IPublishedContent item. /// - /// - /// The IPublishedContent item. - /// - /// - /// The property alias of the property containing the Json data e.g. umbracoFile - /// - /// - /// The crop alias e.g. thumbnail - /// - /// The image url generator. + /// The IPublishedContent item. + /// The property alias of the property containing the JSON data e.g. umbracoFile. + /// The crop alias e.g. thumbnail. + /// The image URL generator. /// The published value fallback. - /// The published url provider. + /// The published URL provider. /// /// The URL of the cropped image. /// @@ -92,74 +75,37 @@ namespace Umbraco.Extensions string cropAlias, IImageUrlGenerator imageUrlGenerator, IPublishedValueFallback publishedValueFallback, - IPublishedUrlProvider publishedUrlProvider) - { - return mediaItem.GetCropUrl( imageUrlGenerator, publishedValueFallback, publishedUrlProvider, propertyAlias: propertyAlias, cropAlias: cropAlias, useCropDimensions: true); - } + IPublishedUrlProvider publishedUrlProvider) => mediaItem.GetCropUrl(imageUrlGenerator, publishedValueFallback, publishedUrlProvider, propertyAlias: propertyAlias, cropAlias: cropAlias, useCropDimensions: true); public static string GetCropUrl(this MediaWithCrops mediaWithCrops, IPublishedValueFallback publishedValueFallback, IPublishedUrlProvider publishedUrlProvider, string propertyAlias, string cropAlias, - IImageUrlGenerator imageUrlGenerator) - { - return mediaWithCrops.GetCropUrl(imageUrlGenerator, publishedValueFallback, publishedUrlProvider, propertyAlias: propertyAlias, cropAlias: cropAlias, useCropDimensions: true); - } + IImageUrlGenerator imageUrlGenerator) => mediaWithCrops.GetCropUrl(imageUrlGenerator, publishedValueFallback, publishedUrlProvider, propertyAlias: propertyAlias, cropAlias: cropAlias, useCropDimensions: true); /// /// Gets the underlying image processing service URL from the IPublishedContent item. /// - /// - /// The IPublishedContent item. - /// - /// The image url generator. + /// The IPublishedContent item. + /// The image URL generator. /// The published value fallback. - /// The published url provider. - /// - /// The width of the output image. - /// - /// - /// The height of the output image. - /// - /// - /// Property alias of the property containing the Json data. - /// - /// - /// The crop alias. - /// - /// - /// Quality percentage of the output image. - /// - /// - /// The image crop mode. - /// - /// - /// The image crop anchor. - /// - /// - /// Use focal point, to generate an output image using the focal point instead of the predefined crop - /// - /// - /// Use crop dimensions to have the output image sized according to the predefined crop sizes, this will override the width and height parameters. - /// - /// - /// Add a serialized date of the last edit of the item to ensure client cache refresh when updated - /// - /// - /// These are any query string parameters (formatted as query strings) that ImageProcessor supports. For example: - /// - /// The published URL provider. + /// The width of the output image. + /// The height of the output image. + /// Property alias of the property containing the JSON data. + /// The crop alias. + /// Quality percentage of the output image. + /// The image crop mode. + /// The image crop anchor. + /// Use focal point, to generate an output image using the focal point instead of the predefined crop. + /// Use crop dimensions to have the output image sized according to the predefined crop sizes, this will override the width and height parameters. + /// Add a serialized date of the last edit of the item to ensure client cache refresh when updated. + /// These are any query string parameters (formatted as query strings) that ImageProcessor supports. For example: + /// - /// - /// - /// - /// Use a dimension as a ratio - /// - /// - /// If the image should be upscaled to requested dimensions - /// + /// ]]> + /// Use a dimension as a ratio. /// /// The URL of the cropped image. /// @@ -179,11 +125,7 @@ namespace Umbraco.Extensions bool useCropDimensions = false, bool cacheBuster = true, string furtherOptions = null, - ImageCropRatioMode? ratioMode = null, - bool upScale = true) - { - return mediaItem.GetCropUrl(imageUrlGenerator, publishedValueFallback, publishedUrlProvider, null, false, width, height, propertyAlias, cropAlias, quality, imageCropMode, imageCropAnchor, preferFocalPoint, useCropDimensions, cacheBuster, furtherOptions, ratioMode, upScale); - } + ImageCropRatioMode? ratioMode = null) => mediaItem.GetCropUrl(imageUrlGenerator, publishedValueFallback, publishedUrlProvider, null, false, width, height, propertyAlias, cropAlias, quality, imageCropMode, imageCropAnchor, preferFocalPoint, useCropDimensions, cacheBuster, furtherOptions, ratioMode); public static string GetCropUrl( this MediaWithCrops mediaWithCrops, @@ -201,12 +143,14 @@ namespace Umbraco.Extensions bool useCropDimensions = false, bool cacheBuster = true, string furtherOptions = null, - ImageCropRatioMode? ratioMode = null, - bool upScale = true) + ImageCropRatioMode? ratioMode = null) { - if (mediaWithCrops == null) throw new ArgumentNullException(nameof(mediaWithCrops)); + if (mediaWithCrops == null) + { + throw new ArgumentNullException(nameof(mediaWithCrops)); + } - return mediaWithCrops.Content.GetCropUrl(imageUrlGenerator, publishedValueFallback, publishedUrlProvider, mediaWithCrops.LocalCrops, false, width, height, propertyAlias, cropAlias, quality, imageCropMode, imageCropAnchor, preferFocalPoint, useCropDimensions, cacheBuster, furtherOptions, ratioMode, upScale); + return mediaWithCrops.Content.GetCropUrl(imageUrlGenerator, publishedValueFallback, publishedUrlProvider, mediaWithCrops.LocalCrops, false, width, height, propertyAlias, cropAlias, quality, imageCropMode, imageCropAnchor, preferFocalPoint, useCropDimensions, cacheBuster, furtherOptions, ratioMode); } private static string GetCropUrl( @@ -227,15 +171,17 @@ namespace Umbraco.Extensions bool useCropDimensions = false, bool cacheBuster = true, string furtherOptions = null, - ImageCropRatioMode? ratioMode = null, - bool upScale = true) + ImageCropRatioMode? ratioMode = null) { - if (mediaItem == null) throw new ArgumentNullException(nameof(mediaItem)); - - var cacheBusterValue = cacheBuster ? mediaItem.UpdateDate.ToFileTimeUtc().ToString(CultureInfo.InvariantCulture) : null; + if (mediaItem == null) + { + throw new ArgumentNullException(nameof(mediaItem)); + } if (mediaItem.HasProperty(propertyAlias) == false || mediaItem.HasValue(propertyAlias) == false) - return string.Empty; + { + return null; + } var mediaItemUrl = mediaItem.MediaUrl(publishedUrlProvider, propertyAlias: propertyAlias); @@ -269,63 +215,35 @@ namespace Umbraco.Extensions } } + var cacheBusterValue = cacheBuster ? mediaItem.UpdateDate.ToFileTimeUtc().ToString(CultureInfo.InvariantCulture) : null; + return GetCropUrl( mediaItemUrl, imageUrlGenerator, localCrops, width, height, cropAlias, quality, imageCropMode, imageCropAnchor, preferFocalPoint, useCropDimensions, - cacheBusterValue, furtherOptions, ratioMode, upScale); + cacheBusterValue, furtherOptions, ratioMode); } /// /// Gets the underlying image processing service URL from the image path. /// - /// - /// The image URL. - /// - /// - /// The width of the output image. - /// - /// - /// The height of the output image. - /// - /// - /// The Json data from the Umbraco Core Image Cropper property editor - /// - /// - /// The crop alias. - /// - /// - /// Quality percentage of the output image. - /// - /// - /// The image crop mode. - /// - /// - /// The image crop anchor. - /// - /// - /// Use focal point to generate an output image using the focal point instead of the predefined crop if there is one - /// - /// - /// Use crop dimensions to have the output image sized according to the predefined crop sizes, this will override the width and height parameters - /// - /// - /// Add a serialized date of the last edit of the item to ensure client cache refresh when updated - /// - /// - /// These are any query string parameters (formatted as query strings) that the underlying image processing service supports. For example: - /// - /// The image URL. + /// The image URL generator. + /// The width of the output image. + /// The height of the output image. + /// The Json data from the Umbraco Core Image Cropper property editor. + /// The crop alias. + /// Quality percentage of the output image. + /// The image crop mode. + /// The image crop anchor. + /// Use focal point to generate an output image using the focal point instead of the predefined crop if there is one. + /// Use crop dimensions to have the output image sized according to the predefined crop sizes, this will override the width and height parameters. + /// Add a serialized date of the last edit of the item to ensure client cache refresh when updated. + /// These are any query string parameters (formatted as query strings) that the underlying image processing service supports. For example: + /// - /// - /// - /// - /// Use a dimension as a ratio - /// - /// - /// If the image should be upscaled to requested dimensions - /// + /// ]]> + /// Use a dimension as a ratio. /// - /// The the URL of the cropped image. + /// The URL of the cropped image. /// public static string GetCropUrl( this string imageUrl, @@ -341,10 +259,12 @@ namespace Umbraco.Extensions bool useCropDimensions = false, string cacheBusterValue = null, string furtherOptions = null, - ImageCropRatioMode? ratioMode = null, - bool upScale = true) + ImageCropRatioMode? ratioMode = null) { - if (string.IsNullOrEmpty(imageUrl)) return string.Empty; + if (string.IsNullOrWhiteSpace(imageUrl)) + { + return null; + } ImageCropperValue cropDataSet = null; if (string.IsNullOrEmpty(imageCropperValue) == false && imageCropperValue.DetectIsJson() && (imageCropMode == ImageCropMode.Crop || imageCropMode == null)) @@ -354,62 +274,31 @@ namespace Umbraco.Extensions return GetCropUrl( imageUrl, imageUrlGenerator, cropDataSet, width, height, cropAlias, quality, imageCropMode, - imageCropAnchor, preferFocalPoint, useCropDimensions, cacheBusterValue, furtherOptions, ratioMode, upScale); + imageCropAnchor, preferFocalPoint, useCropDimensions, cacheBusterValue, furtherOptions, ratioMode); } /// /// Gets the underlying image processing service URL from the image path. /// - /// - /// The image URL. - /// - /// - /// The generator that will process all the options and the image URL to return a full image URLs with all processing options appended - /// - /// - /// - /// The width of the output image. - /// - /// - /// The height of the output image. - /// - /// - /// The crop alias. - /// - /// - /// Quality percentage of the output image. - /// - /// - /// The image crop mode. - /// - /// - /// The image crop anchor. - /// - /// - /// Use focal point to generate an output image using the focal point instead of the predefined crop if there is one - /// - /// - /// Use crop dimensions to have the output image sized according to the predefined crop sizes, this will override the width and height parameters - /// - /// - /// Add a serialized date of the last edit of the item to ensure client cache refresh when updated - /// - /// - /// These are any query string parameters (formatted as query strings) that the underlying image processing service supports. For example: - /// - /// The image URL. + /// The generator that will process all the options and the image URL to return a full image URLs with all processing options appended. + /// The crop data set. + /// The width of the output image. + /// The height of the output image. + /// The crop alias. + /// Quality percentage of the output image. + /// The image crop mode. + /// The image crop anchor. + /// Use focal point to generate an output image using the focal point instead of the predefined crop if there is one. + /// Use crop dimensions to have the output image sized according to the predefined crop sizes, this will override the width and height parameters. + /// Add a serialized date of the last edit of the item to ensure client cache refresh when updated. + /// These are any query string parameters (formatted as query strings) that the underlying image processing service supports. For example: + /// - /// - /// - /// - /// Use a dimension as a ratio - /// - /// - /// If the image should be upscaled to requested dimensions - /// + /// ]]> + /// Use a dimension as a ratio. /// - /// The . + /// The URL of the cropped image. /// public static string GetCropUrl( this string imageUrl, @@ -425,21 +314,23 @@ namespace Umbraco.Extensions bool useCropDimensions = false, string cacheBusterValue = null, string furtherOptions = null, - ImageCropRatioMode? ratioMode = null, - bool upScale = true, - string animationProcessMode = null) + ImageCropRatioMode? ratioMode = null) { - if (string.IsNullOrEmpty(imageUrl)) return string.Empty; + if (string.IsNullOrWhiteSpace(imageUrl)) + { + return null; + } ImageUrlGenerationOptions options; - if (cropDataSet != null && (imageCropMode == ImageCropMode.Crop || imageCropMode == null)) { var crop = cropDataSet.GetCrop(cropAlias); - // if a crop was specified, but not found, return null + // If a crop was specified, but not found, return null if (crop == null && !string.IsNullOrWhiteSpace(cropAlias)) + { return null; + } options = cropDataSet.GetCropBaseOptions(imageUrl, crop, string.IsNullOrWhiteSpace(cropAlias), preferFocalPoint); @@ -464,7 +355,7 @@ namespace Umbraco.Extensions } else { - options = new ImageUrlGenerationOptions (imageUrl) + options = new ImageUrlGenerationOptions(imageUrl) { ImageCropMode = (imageCropMode ?? ImageCropMode.Pad), ImageCropAnchor = imageCropAnchor @@ -474,7 +365,6 @@ namespace Umbraco.Extensions options.Quality = quality; options.Width = ratioMode != null && ratioMode.Value == ImageCropRatioMode.Width ? null : width; options.Height = ratioMode != null && ratioMode.Value == ImageCropRatioMode.Height ? null : height; - options.AnimationProcessMode = animationProcessMode; if (ratioMode == ImageCropRatioMode.Width && height != null) { @@ -502,7 +392,6 @@ namespace Umbraco.Extensions } } - options.UpScale = upScale; options.FurtherOptions = furtherOptions; options.CacheBusterValue = cacheBusterValue; diff --git a/src/Umbraco.Web.Common/Extensions/UrlHelperExtensions.cs b/src/Umbraco.Web.Common/Extensions/UrlHelperExtensions.cs index e7dd5248e1..a6dd4ac1ca 100644 --- a/src/Umbraco.Web.Common/Extensions/UrlHelperExtensions.cs +++ b/src/Umbraco.Web.Common/Extensions/UrlHelperExtensions.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Collections.Generic; using System.Globalization; using System.Linq; @@ -247,7 +247,6 @@ namespace Umbraco.Extensions bool cacheBuster = true, string furtherOptions = null, ImageCropRatioMode? ratioMode = null, - bool upScale = true, bool htmlEncode = true) { if (mediaItem == null) @@ -256,8 +255,8 @@ namespace Umbraco.Extensions } var url = mediaItem.GetCropUrl(width, height, propertyAlias, cropAlias, quality, imageCropMode, - imageCropAnchor, preferFocalPoint, useCropDimensions, cacheBuster, furtherOptions, ratioMode, - upScale); + imageCropAnchor, preferFocalPoint, useCropDimensions, cacheBuster, furtherOptions, ratioMode); + return CreateHtmlString(url, htmlEncode); } @@ -274,15 +273,14 @@ namespace Umbraco.Extensions string cacheBusterValue = null, string furtherOptions = null, ImageCropRatioMode? ratioMode = null, - bool upScale = true, bool htmlEncode = true) { if (imageCropperValue == null) return HtmlString.Empty; var imageUrl = imageCropperValue.Src; var url = imageUrl.GetCropUrl(imageCropperValue, width, height, cropAlias, quality, imageCropMode, - imageCropAnchor, preferFocalPoint, useCropDimensions, cacheBusterValue, furtherOptions, ratioMode, - upScale); + imageCropAnchor, preferFocalPoint, useCropDimensions, cacheBusterValue, furtherOptions, ratioMode); + return CreateHtmlString(url, htmlEncode); } diff --git a/src/Umbraco.Web.UI.Client/src/common/resources/imageurlgenerator.resource.js b/src/Umbraco.Web.UI.Client/src/common/resources/imageurlgenerator.resource.js index a937cd2675..dd65f89526 100644 --- a/src/Umbraco.Web.UI.Client/src/common/resources/imageurlgenerator.resource.js +++ b/src/Umbraco.Web.UI.Client/src/common/resources/imageurlgenerator.resource.js @@ -1,4 +1,4 @@ -/** +/** * @ngdoc service * @name umbraco.resources.imageUrlGeneratorResource * @function @@ -11,14 +11,14 @@ function imageUrlGeneratorResource($http, umbRequestHelper) { - function getCropUrl(mediaPath, width, height, imageCropMode, animationProcessMode) { + function getCropUrl(mediaPath, width, height, imageCropMode) { return umbRequestHelper.resourcePromise( $http.get( umbRequestHelper.getApiUrl( "imageUrlGeneratorApiBaseUrl", "GetCropUrl", - { mediaPath, width, height, imageCropMode, animationProcessMode })), + { mediaPath, width, height, imageCropMode })), 'Failed to get crop URL'); } diff --git a/src/Umbraco.Web.UI.Client/src/common/services/mediahelper.service.js b/src/Umbraco.Web.UI.Client/src/common/services/mediahelper.service.js index 1b3765a5f5..e98a597e76 100644 --- a/src/Umbraco.Web.UI.Client/src/common/services/mediahelper.service.js +++ b/src/Umbraco.Web.UI.Client/src/common/services/mediahelper.service.js @@ -1,4 +1,4 @@ -/** +/** * @ngdoc service * @name umbraco.services.mediaHelper * @description A helper object used for dealing with media items @@ -408,16 +408,20 @@ function mediaHelper(umbRequestHelper, $http, $log) { * @param {string} imagePath Raw image path * @param {object} options Object describing image generation parameters: * { - * animationProcessMode: - * cacheBusterValue: + * width: + * height: * focalPoint: { * left: * top: * }, - * height: * mode: - * upscale: - * width: + * cacheBusterValue: + * crop: { + * x1: + * x2: + * y1: + * y2: + * }, * } */ getProcessedImageUrl: function (imagePath, options) { @@ -433,18 +437,16 @@ function mediaHelper(umbRequestHelper, $http, $log) { "GetProcessedImageUrl", { imagePath, - animationProcessMode: options.animationProcessMode, - cacheBusterValue: options.cacheBusterValue, + width: options.width, + height: options.height, focalPointLeft: options.focalPoint ? options.focalPoint.left : null, focalPointTop: options.focalPoint ? options.focalPoint.top : null, - height: options.height, mode: options.mode, - upscale: options.upscale || false, - width: options.width, + cacheBusterValue: options.cacheBusterValue, cropX1: options.crop ? options.crop.x1 : null, cropX2: options.crop ? options.crop.x2 : null, cropY1: options.crop ? options.crop.y1 : null, - cropY2: options.crop ? options.crop.y : null + cropY2: options.crop ? options.crop.y2 : null })), "Failed to retrieve processed image URL for image: " + imagePath); } diff --git a/src/Umbraco.Web.UI.Client/src/common/services/tinymce.service.js b/src/Umbraco.Web.UI.Client/src/common/services/tinymce.service.js index b83367ef6e..2738883b15 100644 --- a/src/Umbraco.Web.UI.Client/src/common/services/tinymce.service.js +++ b/src/Umbraco.Web.UI.Client/src/common/services/tinymce.service.js @@ -306,8 +306,8 @@ function tinyMceService($rootScope, $q, imageHelper, $locale, $http, $timeout, s if (imgUrl) { mediaHelper.getProcessedImageUrl(imgUrl, { - height: newSize.height, - width: newSize.width + width: newSize.width, + height: newSize.height }) .then(function (resizedImgUrl) { editor.dom.setAttrib(imageDomElement, 'data-mce-src', resizedImgUrl); @@ -1522,15 +1522,13 @@ function tinyMceService($rootScope, $q, imageHelper, $locale, $http, $timeout, s args.editor.on('ObjectResized', function (e) { var srcAttr = $(e.target).attr("src"); var path = srcAttr.split("?")[0]; - mediaHelper.getProcessedImageUrl(path, - { - height: e.height, - moded: "max", - width: e.width - }) - .then(function (resizedPath) { - $(e.target).attr("data-mce-src", resizedPath); - }); + mediaHelper.getProcessedImageUrl(path, { + width: e.width, + height: e.height, + mode: "max" + }).then(function (resizedPath) { + $(e.target).attr("data-mce-src", resizedPath); + }); syncContent(); });