private static void WriteResizedImage(string cachedImageServerPath, string imageServerPath,
                                              ResizeSettings settings)
        {
            var sizeLimits = Config.Current.Plugins.Get <SizeLimiting>();

            if (sizeLimits != null)
            {
                sizeLimits.Limits.TotalBehavior = SizeLimits.TotalSizeBehavior.IgnoreLimits;
            }

            if (settings.WasOneSpecified(GrayscaleFilter.SupportedKeys.ToArray()))
            {
                Config.Current.Plugins.GetOrInstall <GrayscaleFilter>();
            }
            if (settings.WasOneSpecified(BlurFilter.SupportedKeys.ToArray()))
            {
                Config.Current.Plugins.GetOrInstall <BlurFilter>();
            }

            for (int i = 0; i < 10; i++)
            {
                try
                {
                    WriteResizedFile(cachedImageServerPath, imageServerPath, settings);
                    break;
                }
                catch
                {
                    Thread.Sleep(100);
                }
            }
        }
        private static void WriteResizedImage(string cachedImageServerPath, string imageServerPath,
                                              ResizeSettings settings)
        {
            var sizeLimits = Config.Current.Plugins.Get<SizeLimiting>();
            if (sizeLimits != null)
            {
                sizeLimits.Limits.TotalBehavior = SizeLimits.TotalSizeBehavior.IgnoreLimits;
            }

            if (settings.WasOneSpecified(GrayscaleFilter.SupportedKeys.ToArray()))
            {
                Config.Current.Plugins.GetOrInstall<GrayscaleFilter>();
            }
            if (settings.WasOneSpecified(BlurFilter.SupportedKeys.ToArray()))
            {
                Config.Current.Plugins.GetOrInstall<BlurFilter>();
            }

            for (int i = 0; i < 10; i++)
            {
                try
                {
                    WriteResizedFile(cachedImageServerPath, imageServerPath, settings);
                    break;
                }
                catch
                {
                    Thread.Sleep(100);
                }
            }
        }
        private string GetResizedUrl(string url, ResizeSettings settings)
        {
            try
            {
                if (settings.WasOneSpecified(GrayscaleFilter.FilterKey))
                {
                    Config.Current.Plugins.GetOrInstall<GrayscaleFilter>();
                }

                if (!url.StartsWith("/"))
                {
                    url = "/" + url;
                }

                if (!IsResizeSettingsValid(settings))
                {
                    return "";
                }

                var imageServerPath = GetServerPath(url);
                if (!File.Exists(imageServerPath))
                {
                    return "";
                }

                imageServerPath = FilterUnsupportedFiles(imageServerPath);
                if (string.IsNullOrWhiteSpace(imageServerPath)) 
                    return "";

                var cachedImagePath = GetImageCachePath(url, settings);
                string cachedImageServerPath = GetServerPath(cachedImagePath);

                if (!File.Exists(cachedImageServerPath))
                {
                    WriteResizedImage(cachedImageServerPath, imageServerPath, settings);
                }
                else
                {
                    var cacheFileInfo = new FileInfo(cachedImageServerPath);
                    var imageFileInfo = new FileInfo(imageServerPath);
                    if (cacheFileInfo.LastWriteTimeUtc < imageFileInfo.LastWriteTimeUtc)
                    {
                        WriteResizedImage(cachedImageServerPath, imageServerPath, settings);
                    }
                }
                return cachedImagePath;
            }
            catch
            {
                return string.Empty;
            }
        }