Merge pull request #1474 from umbraco/temp-U4-8963
U4-8963 Updates for ImageProcessor parameters to support background c…
This commit is contained in:
@@ -367,5 +367,17 @@ namespace Umbraco.Tests.PropertyEditors
|
||||
var urlString = mediaPath.GetCropUrl(imageCropperValue: cropperJson, height: 200);
|
||||
Assert.AreEqual(mediaPath + "?anchor=center&mode=crop&height=200", urlString);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Test to check result when using a background color with padding
|
||||
/// </summary>
|
||||
[Test]
|
||||
public void GetCropUrl_BackgroundColorParameter()
|
||||
{
|
||||
var cropperJson = "{\"focalPoint\": {\"left\": 0.5,\"top\": 0.5},\"src\": \"" + mediaPath + "\",\"crops\": [{\"alias\": \"home\",\"width\": 270,\"height\": 161}]}";
|
||||
|
||||
var urlString = mediaPath.GetCropUrl(400, 400, cropperJson, imageCropMode: ImageCropMode.Pad, backgroundColor: "fff");
|
||||
Assert.AreEqual(mediaPath + "?mode=pad&width=400&height=400&bgcolor=fff", urlString);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -228,12 +228,13 @@ namespace Umbraco.Web
|
||||
bool cacheBuster = true,
|
||||
string furtherOptions = null,
|
||||
ImageCropRatioMode? ratioMode = null,
|
||||
bool upScale = true)
|
||||
bool upScale = true,
|
||||
string backgroundColor = null)
|
||||
{
|
||||
return
|
||||
new HtmlString(mediaItem.GetCropUrl(width, height, propertyAlias, cropAlias, quality, imageCropMode,
|
||||
imageCropAnchor, preferFocalPoint, useCropDimensions, cacheBuster, furtherOptions, ratioMode,
|
||||
upScale));
|
||||
upScale, backgroundColor));
|
||||
}
|
||||
|
||||
[Obsolete("Use the UrlHelper.GetCropUrl extension instead")]
|
||||
@@ -252,12 +253,13 @@ namespace Umbraco.Web
|
||||
string cacheBusterValue = null,
|
||||
string furtherOptions = null,
|
||||
ImageCropRatioMode? ratioMode = null,
|
||||
bool upScale = true)
|
||||
bool upScale = true,
|
||||
string backgroundColor = null)
|
||||
{
|
||||
return
|
||||
new HtmlString(imageUrl.GetCropUrl(width, height, imageCropperValue, cropAlias, quality, imageCropMode,
|
||||
imageCropAnchor, preferFocalPoint, useCropDimensions, cacheBusterValue, furtherOptions, ratioMode,
|
||||
upScale));
|
||||
upScale, backgroundColor));
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
@@ -91,10 +91,13 @@ namespace Umbraco.Web
|
||||
/// </param>
|
||||
/// <param name="ratioMode">
|
||||
/// Use a dimension as a ratio
|
||||
/// </param>
|
||||
/// </param>
|
||||
/// <param name="upScale">
|
||||
/// If the image should be upscaled to requested dimensions
|
||||
/// </param>
|
||||
/// </param>
|
||||
/// <param name="backgroundColor">
|
||||
/// Changes the background color of the image. Used when adding a background when resizing image formats without an alpha channel.
|
||||
/// </param>
|
||||
/// <returns>
|
||||
/// The <see cref="string"/>.
|
||||
/// </returns>
|
||||
@@ -112,7 +115,8 @@ namespace Umbraco.Web
|
||||
bool cacheBuster = true,
|
||||
string furtherOptions = null,
|
||||
ImageCropRatioMode? ratioMode = null,
|
||||
bool upScale = true)
|
||||
bool upScale = true,
|
||||
string backgroundColor = null)
|
||||
{
|
||||
if (mediaItem == null) throw new ArgumentNullException("mediaItem");
|
||||
|
||||
@@ -132,7 +136,7 @@ namespace Umbraco.Web
|
||||
mediaItemUrl = stronglyTyped.Src;
|
||||
return GetCropUrl(
|
||||
mediaItemUrl, stronglyTyped, width, height, cropAlias, quality, imageCropMode, imageCropAnchor, preferFocalPoint, useCropDimensions,
|
||||
cacheBusterValue, furtherOptions, ratioMode, upScale);
|
||||
cacheBusterValue, furtherOptions, ratioMode, upScale, backgroundColor);
|
||||
}
|
||||
|
||||
//this shouldn't be the case but we'll check
|
||||
@@ -143,14 +147,14 @@ namespace Umbraco.Web
|
||||
mediaItemUrl = stronglyTyped.Src;
|
||||
return GetCropUrl(
|
||||
mediaItemUrl, stronglyTyped, width, height, cropAlias, quality, imageCropMode, imageCropAnchor, preferFocalPoint, useCropDimensions,
|
||||
cacheBusterValue, furtherOptions, ratioMode, upScale);
|
||||
cacheBusterValue, furtherOptions, ratioMode, upScale, backgroundColor);
|
||||
}
|
||||
|
||||
//it's a single string
|
||||
mediaItemUrl = cropperValue.ToString();
|
||||
return GetCropUrl(
|
||||
mediaItemUrl, width, height, mediaItemUrl, cropAlias, quality, imageCropMode, imageCropAnchor, preferFocalPoint, useCropDimensions,
|
||||
cacheBusterValue, furtherOptions, ratioMode, upScale);
|
||||
cacheBusterValue, furtherOptions, ratioMode, upScale, backgroundColor);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -198,6 +202,9 @@ namespace Umbraco.Web
|
||||
/// <param name="upScale">
|
||||
/// If the image should be upscaled to requested dimensions
|
||||
/// </param>
|
||||
/// <param name="backgroundColor">
|
||||
/// Changes the background color of the image. Used when adding a background when resizing image formats without an alpha channel.
|
||||
/// </param>
|
||||
/// <returns>
|
||||
/// The <see cref="string"/>.
|
||||
/// </returns>
|
||||
@@ -215,7 +222,8 @@ namespace Umbraco.Web
|
||||
string cacheBusterValue = null,
|
||||
string furtherOptions = null,
|
||||
ImageCropRatioMode? ratioMode = null,
|
||||
bool upScale = true)
|
||||
bool upScale = true,
|
||||
string backgroundColor = null)
|
||||
{
|
||||
if (string.IsNullOrEmpty(imageUrl)) return string.Empty;
|
||||
|
||||
@@ -226,7 +234,7 @@ namespace Umbraco.Web
|
||||
}
|
||||
return GetCropUrl(
|
||||
imageUrl, cropDataSet, width, height, cropAlias, quality, imageCropMode,
|
||||
imageCropAnchor, preferFocalPoint, useCropDimensions, cacheBusterValue, furtherOptions, ratioMode, upScale);
|
||||
imageCropAnchor, preferFocalPoint, useCropDimensions, cacheBusterValue, furtherOptions, ratioMode, upScale, backgroundColor);
|
||||
}
|
||||
|
||||
public static string GetCropUrl(
|
||||
@@ -243,7 +251,8 @@ namespace Umbraco.Web
|
||||
string cacheBusterValue = null,
|
||||
string furtherOptions = null,
|
||||
ImageCropRatioMode? ratioMode = null,
|
||||
bool upScale = true)
|
||||
bool upScale = true,
|
||||
string backgroundColor = null)
|
||||
{
|
||||
if (string.IsNullOrEmpty(imageUrl) == false)
|
||||
{
|
||||
@@ -350,6 +359,11 @@ namespace Umbraco.Web
|
||||
imageProcessorUrl.Append("&upscale=false");
|
||||
}
|
||||
|
||||
if (backgroundColor != null)
|
||||
{
|
||||
imageProcessorUrl.Append("&bgcolor=" + backgroundColor);
|
||||
}
|
||||
|
||||
if (furtherOptions != null)
|
||||
{
|
||||
imageProcessorUrl.Append(furtherOptions);
|
||||
|
||||
@@ -114,6 +114,9 @@ namespace Umbraco.Web
|
||||
/// Whether to HTML encode this URL - default is true - w3c standards require html attributes to be html encoded but this can be
|
||||
/// set to false if using the result of this method for CSS.
|
||||
/// </param>
|
||||
/// <param name="backgroundColor">
|
||||
/// Changes the background color of the image. Used when adding a background when resizing image formats without an alpha channel.
|
||||
/// </param>
|
||||
/// <returns>
|
||||
/// The <see cref="string"/>.
|
||||
/// </returns>
|
||||
@@ -132,11 +135,12 @@ namespace Umbraco.Web
|
||||
string furtherOptions = null,
|
||||
ImageCropRatioMode? ratioMode = null,
|
||||
bool upScale = true,
|
||||
bool htmlEncode = true)
|
||||
bool htmlEncode = true,
|
||||
string backgroundColor = null)
|
||||
{
|
||||
var url = mediaItem.GetCropUrl(width, height, propertyAlias, cropAlias, quality, imageCropMode,
|
||||
imageCropAnchor, preferFocalPoint, useCropDimensions, cacheBuster, furtherOptions, ratioMode,
|
||||
upScale);
|
||||
upScale, backgroundColor);
|
||||
return htmlEncode ? new HtmlString(HttpUtility.HtmlEncode(url)) : new HtmlString(url);
|
||||
}
|
||||
|
||||
@@ -190,6 +194,9 @@ namespace Umbraco.Web
|
||||
/// Whether to HTML encode this URL - default is true - w3c standards require html attributes to be html encoded but this can be
|
||||
/// set to false if using the result of this method for CSS.
|
||||
/// </param>
|
||||
/// <param name="backgroundColor">
|
||||
/// Changes the background color of the image. Used when adding a background when resizing image formats without an alpha channel.
|
||||
/// </param>
|
||||
/// <returns>
|
||||
/// The <see cref="string"/>.
|
||||
/// </returns>
|
||||
@@ -208,11 +215,12 @@ namespace Umbraco.Web
|
||||
string furtherOptions = null,
|
||||
ImageCropRatioMode? ratioMode = null,
|
||||
bool upScale = true,
|
||||
bool htmlEncode = true)
|
||||
bool htmlEncode = true,
|
||||
string backgroundColor = null)
|
||||
{
|
||||
var url = imageUrl.GetCropUrl(width, height, imageCropperValue, cropAlias, quality, imageCropMode,
|
||||
imageCropAnchor, preferFocalPoint, useCropDimensions, cacheBusterValue, furtherOptions, ratioMode,
|
||||
upScale);
|
||||
upScale, backgroundColor);
|
||||
return htmlEncode ? new HtmlString(HttpUtility.HtmlEncode(url)) : new HtmlString(url);
|
||||
}
|
||||
|
||||
@@ -333,7 +341,5 @@ namespace Umbraco.Web
|
||||
{
|
||||
return url.SurfaceAction(action, typeof (T), additionalRouteVals);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user