Search code examples
c#azureimageresizerazure-functions

ImageResizer: Disable size limitation of resizing


I am using the ImageResizer (https://imageresizing.net/) library in a Azure Function which returns resized images stored in a Azure Storage Account.

Its working fine so far, but it has the limitation of resizing to maximum 3200 pixels. (https://imageresizing.net/docs/v4/plugins/sizelimiting)

Since i'm using a Azure Function I can't access a web.config to disable this limitation. Can I disable this limitation via code (maybe ResizeSettings)?

Thanks.


Solution

  • Normally you'd remove the SizeLimiting plugin in Application_Start but we don't currently give you any hooks in Azure Functions to run startup code. We've got an issue tracking that here in our repo.

    However, you can still remove the plugin in your function code before doing any image processing, e.g.:

    using ImageResizer;
    using ImageResizer.Plugins.Basic;
    
    public static void Run(..., TraceWriter log)
    {
        RemoveSizeLimiter(log);
    
        ...
    }
    
    private static void RemoveSizeLimiter(TraceWriter log)
    {
        var config = ImageResizer.Configuration.Config.Current;
        var sizeLimiter = config.Plugins.Get<SizeLimiting>();
        log.Info("SizeLimiter installed: " + (sizeLimiter != null).ToString());
    
        if (sizeLimiter != null)
        {
            log.Info("Uninstalling SizeLimiter");
            sizeLimiter.Uninstall(config);
        }
    }
    

    If you run this function multiple times, you'll see that the plugin is removed from the static Config.PlugIns collection the first time, and stays removed for the lifetime of the App Domain.