Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Bo Jacobsen 610 posts 2409 karma points
    May 18, 2022 @ 09:52
    Bo Jacobsen
    0

    is there a way to Post Processing images on request

    Hi all.

    Can we intercept image request and return a manipulated image in Umbraco 9 with ImageSharp IRequestParser?

    In Umbraco 8 we could use the ImageProcessingModule.ValidatingRequest and the ImageProcessingModule.OnPostProcessing.

    Can we do something similar in Umbraco 9?

  • Bo Jacobsen 610 posts 2409 karma points
    Jul 12, 2022 @ 08:53
    Bo Jacobsen
    101

    We found a solution.

    We can hook into the process this way.

    public class CustomWebProcessor : IImageWebProcessor
    {
            private const string QueryStringName = "custom";
    
            public IEnumerable<string> Commands => new[] { QueryStringName };
    
            public FormattedImage Process(FormattedImage image, ILogger logger, IDictionary<string, string> commands, CommandParser parser, CultureInfo culture)
            {
                var QueryStringValue = parser.ParseValue<int>(commands.GetValueOrDefault(QueryStringName), culture);
                image.Image.Mutate(ctx => ctx.Brightness(QueryStringValue));
                return image;
            }
     }
    

    and then make a static helper to add it to the builder.

    public static IUmbracoBuilder AddImageWebProcessor(this IUmbracoBuilder builder)
    {
        builder.Services.TryAddEnumerable(ServiceDescriptor.Singleton<IImageWebProcessor, CustomWebProcessor>());
        return builder;
    }
    
  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies