Apachai.PictureContentModule.EnsureSmallAvailable C# (CSharp) Method

EnsureSmallAvailable() private method

private EnsureSmallAvailable ( IManosContext ctx, string path ) : string
ctx IManosContext
path string
return string
        string EnsureSmallAvailable(IManosContext ctx, string path)
        {
            if (!Directory.Exists (smallCache))
                Directory.CreateDirectory (smallCache);

            var newPath = Path.Combine (smallCache, Path.GetFileName (path));
            if (File.Exists (newPath))
                return newPath;

            Task.Factory.StartNew (() => {
                var original = Bitmap.FromFile (path);
                int width = 0, height = 0;
                if (original.Width >= original.Height) {
                    width = smallMax;
                    height = original.Height * smallMax / original.Width;
                } else {
                    height = smallMax;
                    width = original.Width * smallMax / original.Height;
                }

                var newPic = new Bitmap (original, width, height);
                newPic.Save (newPath, System.Drawing.Imaging.ImageFormat.Jpeg);

                ServeImage (ctx, newPath);
            });

            return null;
        }