diff --git a/src/Umbraco.Tests/PropertyEditors/ImageCropperTest.cs b/src/Umbraco.Tests/PropertyEditors/ImageCropperTest.cs
index 771d65dcf5..8a17802c25 100644
--- a/src/Umbraco.Tests/PropertyEditors/ImageCropperTest.cs
+++ b/src/Umbraco.Tests/PropertyEditors/ImageCropperTest.cs
@@ -34,5 +34,12 @@ namespace Umbraco.Tests.PropertyEditors
Assert.AreEqual(mediaPath + "?center=0.80827067669172936,0.96&mode=crop&width=100&height=100", urlString);
}
+ [Test]
+ public void GetCropUrlFurtherOptionsTest()
+ {
+ var urlString = mediaPath.GetCropUrl(imageCropperValue: cropperJson, width: 200, height: 300, cacheBuster: false, furtherOptions: "&filter=comic&roundedcorners=radius-26|bgcolor-fff");
+ Assert.AreEqual(mediaPath + "?center=0.80827067669172936,0.96&mode=crop&width=200&height=300&filter=comic&roundedcorners=radius-26|bgcolor-fff", urlString);
+ }
+
}
}
\ No newline at end of file
diff --git a/src/Umbraco.Web/ImageCropperTemplateExtensions.cs b/src/Umbraco.Web/ImageCropperTemplateExtensions.cs
index 97191bcd38..5db8403edd 100644
--- a/src/Umbraco.Web/ImageCropperTemplateExtensions.cs
+++ b/src/Umbraco.Web/ImageCropperTemplateExtensions.cs
@@ -10,20 +10,90 @@ using Umbraco.Web.PropertyEditors;
namespace Umbraco.Web
{
+ ///
+ /// Provides extension methods for getting ImageProcessor Url from the core Image Cropper property editor
+ ///
public static class ImageCropperTemplateExtensions
{
-
+ ///
+ /// Gets the ImageProcessor Url by the crop alias (from the "umbracoFile" property alias) on the IPublishedContent item
+ ///
+ ///
+ /// The IPublishedContent item.
+ ///
+ ///
+ /// The crop alias e.g. thumbnail
+ ///
+ ///
+ /// The ImageProcessor.Web Url.
+ ///
public static string GetCropUrl(this IPublishedContent mediaItem, string cropAlias)
{
- return mediaItem.GetCropUrl(Constants.Conventions.Media.File, cropAlias);
+ return mediaItem.GetCropUrl(cropAlias: cropAlias, useCropDimensions: true);
}
- // this only takes the crop json into account
+ ///
+ /// Gets the ImageProcessor 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 ImageProcessor.Web Url.
+ ///
public static string GetCropUrl(this IPublishedContent mediaItem, string propertyAlias, string cropAlias)
{
return mediaItem.GetCropUrl(propertyAlias: propertyAlias, cropAlias: cropAlias, useCropDimensions: true);
}
+ ///
+ /// Gets the ImageProcessor Url from the IPublishedContent item.
+ ///
+ ///
+ /// The IPublishedContent item.
+ ///
+ ///
+ /// The width of the output image.
+ ///
+ ///
+ /// The height of the output image.
+ ///
+ ///
+ /// Quality percentage of the output image.
+ ///
+ ///
+ /// The image crop mode.
+ ///
+ ///
+ /// The image crop anchor.
+ ///
+ ///
+ /// Property alias of the property containing the Json data.
+ ///
+ ///
+ /// The crop alias.
+ ///
+ ///
+ /// 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 random number at the end of the generated string
+ ///
+ ///
+ /// The further options.
+ ///
+ ///
+ /// The .
+ ///
public static string GetCropUrl(
this IPublishedContent mediaItem,
int? width = null,
@@ -63,6 +133,48 @@ namespace Umbraco.Web
: string.Empty;
}
+ ///
+ /// Gets the ImageProcessor Url from the image path.
+ ///
+ ///
+ /// The image url.
+ ///
+ ///
+ /// The width of the output image.
+ ///
+ ///
+ /// The height of the output image.
+ ///
+ ///
+ /// Quality percentage of the output image.
+ ///
+ ///
+ /// The image crop mode.
+ ///
+ ///
+ /// The image crop anchor.
+ ///
+ ///
+ /// The Json data from the Umbraco Core Image Cropper property editor
+ ///
+ ///
+ /// The crop alias.
+ ///
+ ///
+ /// 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 random number at the end of the generated string
+ ///
+ ///
+ /// The further options.
+ ///
+ ///
+ /// The .
+ ///
public static string GetCropUrl(
this string imageUrl,
int? width = null,
@@ -77,22 +189,23 @@ namespace Umbraco.Web
bool cacheBuster = true,
string furtherOptions = null)
{
- if (!string.IsNullOrEmpty(imageUrl))
+ if (string.IsNullOrEmpty(imageUrl) == false)
{
var imageResizerUrl = new StringBuilder();
- if (!string.IsNullOrEmpty(imageCropperValue) && imageCropperValue.DetectIsJson())
+ if (string.IsNullOrEmpty(imageCropperValue) == false && imageCropperValue.DetectIsJson())
{
var cropDataSet = imageCropperValue.SerializeToCropDataSet();
if (cropDataSet != null)
{
var cropUrl = cropDataSet.GetCropUrl(cropAlias, false, useFocalPoint, cacheBuster);
- // if crop alias has been specified but not found we should return null
+ // if crop alias has been specified but not found in the Json we should return null
if (string.IsNullOrEmpty(cropAlias) == false && cropUrl == null)
{
return null;
}
+
imageResizerUrl.Append(cropDataSet.Src);
imageResizerUrl.Append(cropDataSet.GetCropUrl(cropAlias, useCropDimensions, useFocalPoint, cacheBuster));
}
@@ -104,6 +217,7 @@ namespace Umbraco.Web
{
imageCropMode = ImageCropMode.Pad;
}
+
imageResizerUrl.Append("?mode=" + imageCropMode.ToString().ToLower());
if (imageCropAnchor != null)
@@ -133,10 +247,9 @@ namespace Umbraco.Web
}
return imageResizerUrl.ToString();
-
}
+
return string.Empty;
}
-
}
}