Ejemplo n.º 1
0
        public override async Task ProcessAsync(TagHelperContext context, TagHelperOutput output)
        {
            if (!ImageWidth.HasValue && !ImageHeight.HasValue && String.IsNullOrEmpty(ImageProfile))
            {
                return;
            }

            var imgSrc = output.Attributes["src"]?.Value.ToString() ?? Src;

            if (string.IsNullOrEmpty(imgSrc))
            {
                return;
            }

            IDictionary <string, string> queryStringParams = null;

            if (!String.IsNullOrEmpty(ImageProfile))
            {
                queryStringParams = await _mediaProfileService.GetMediaProfileCommands(ImageProfile);
            }

            var resizedSrc = ImageSharpUrlFormatter.GetImageResizeUrl(imgSrc, queryStringParams, ImageWidth, ImageHeight, ResizeMode, ImageQuality, ImageFormat, ImageAnchor, ImageBackgroundColor);

            if (_mediaOptions.UseTokenizedQueryString)
            {
                resizedSrc = _mediaTokenService.AddTokenToPath(resizedSrc);
            }

            output.Attributes.SetAttribute("src", resizedSrc);
        }
Ejemplo n.º 2
0
    /// <summary>
    /// Returns a URL with custom resizing parameters for a media profile for an existing image path.
    /// </summary>
    public static async Task <string> ImageProfileResizeUrlAsync(this IOrchardHelper orchardHelper, string imagePath, string imageProfile, int?width = null, int?height = null, ResizeMode resizeMode = ResizeMode.Undefined, int?quality = null, Format format = Format.Undefined, Anchor anchor = null, string bgcolor = null)
    {
        var mediaProfileService = orchardHelper.HttpContext.RequestServices.GetRequiredService <IMediaProfileService>();
        var queryStringParams   = await mediaProfileService.GetMediaProfileCommands(imageProfile);

        var resizedUrl = ImageSharpUrlFormatter.GetImageResizeUrl(imagePath, queryStringParams, width, height, resizeMode, quality, format, anchor, bgcolor);

        return(orchardHelper.TokenizeUrl(resizedUrl));
    }
        public override void Process(TagHelperContext context, TagHelperOutput output)
        {
            if (!ImageWidth.HasValue && !ImageHeight.HasValue)
            {
                return;
            }

            var imgSrc = output.Attributes["src"]?.Value.ToString() ?? Src;

            if (string.IsNullOrEmpty(imgSrc))
            {
                return;
            }

            var resizedSrc = ImageSharpUrlFormatter.GetImageResizeUrl(imgSrc, ImageWidth, ImageHeight, ResizeMode);

            output.Attributes.SetAttribute("src", resizedSrc);
        }
 /// <summary>
 /// Returns a URL with custom resizing parameters for an existing image path.
 /// </summary>
 public static string ImageResizeUrl(this IOrchardHelper orchardHelper, string imagePath, int?width = null, int?height = null, ResizeMode resizeMode = ResizeMode.Undefined)
 {
     return(ImageSharpUrlFormatter.GetImageResizeUrl(imagePath, width, height, resizeMode));
 }
Ejemplo n.º 5
0
    /// <summary>
    /// Returns a URL with custom resizing parameters for an existing image path.
    /// </summary>
    public static string ImageResizeUrl(this IOrchardHelper orchardHelper, string imagePath, int?width = null, int?height = null, ResizeMode resizeMode = ResizeMode.Undefined, int?quality = null, Format format = Format.Undefined, Anchor anchor = null, string bgcolor = null)
    {
        var resizedUrl = ImageSharpUrlFormatter.GetImageResizeUrl(imagePath, null, width, height, resizeMode, quality, format, anchor, bgcolor);

        return(orchardHelper.TokenizeUrl(resizedUrl));
    }