Skip to content

Instantly share code, notes, and snippets.

@Azadehkhojandi
Created November 7, 2016 05:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Azadehkhojandi/4a0417d535cb5cd0e4ba3e26356eb430 to your computer and use it in GitHub Desktop.
Save Azadehkhojandi/4a0417d535cb5cd0e4ba3e26356eb430 to your computer and use it in GitHub Desktop.
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;
}
}
}
@Azadehkhojandi
Copy link
Author

Get sitecore media url

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment