Created
November 7, 2016 05:51
-
-
Save Azadehkhojandi/4a0417d535cb5cd0e4ba3e26356eb430 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using Sitecore.StringExtensions; | |
namespace SOPA.Framework.Helpers | |
{ | |
using Sitecore.Data; | |
using Sitecore.Resources.Media; | |
public static class MediaHelper | |
{ | |
public static string GetImageUrl(string imageSrc, int width, int height, bool allowStretch, bool protectAssetUrl) | |
{ | |
if (imageSrc.IsNullOrEmpty()) | |
{ | |
return $"http://placehold.it/{width}x{height}"; | |
} | |
var imageUrl = $"{imageSrc}?w={width}&h={height}&as={(allowStretch ? "1" : "0")}"; | |
if (protectAssetUrl) | |
{ | |
return HashingUtils.ProtectAssetUrl(imageUrl); | |
} | |
return imageUrl; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Get sitecore media url