Search code examples
c#imageprocessor

How can I apply multiple "filters" in one ImageProcessor.Web request?


I'm using the ImageProcessor.Web library in a .NET application. It is all working and seems great, but I'm wondering if there is a way to apply multiple filters (https://imageprocessor.org/imageprocessor-web/imageprocessingmodule/filter/) in the one request?

I'm specifically wanting to convert images to B&W, then invert them upon request: e.g. /myimage.jpg?filter=blackwhite&filter=invert


Solution

  • The System.Drawing ColorMatrix class does not provide methods to multiply matrices to combine values which is how filters would normally be combined.

    https://learn.microsoft.com/en-us/dotnet/api/system.drawing.imaging.colormatrix?view=netframework-4.8

    Because of this I never designed the filter rules to allow for multiple combined requests.

    However, there is nothing to stop you implementing and registering your own IWebGraphicsProcessor that allowed combining the commands into a single command.