Exemplo n.º 1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="context"></param>
        /// <param name="next"></param>
        /// <returns></returns>
        public async Task InvokeAsync(HttpContext context, RequestDelegate next)
        {
            var options = this.options.Value;

            if (options.RequestConstrainAsync is not null)
            {
                if (!await options.RequestConstrainAsync.Invoke(context))
                {
                    return;
                }
            }

            var request = context.Request;

            var model = new ImageResizeModel {
                ImagePath = request.Path
            };
            var imagePath = model.Resize(options)?.Replace(Path.DirectorySeparatorChar, '/');

            if (imagePath.IsNotNullOrEmpty())
            {
                context.Response.Redirect($"/{imagePath}");
            }

            await Task.CompletedTask;
        }
Exemplo n.º 2
0
        public static byte[] ImageResizer(byte[] myBytes, string BasePath, List <ImageSize> imageResizeList)
        {
            try
            {
                List <ImageResizeModel> list = new List <Models.ImageResizeModel>();
                ImageResizeModel        imageResizeModel;
                Stream sourcePath = new MemoryStream(myBytes);
                foreach (var image in imageResizeList)
                {
                    Bitmap original = new Bitmap(sourcePath);

                    imageResizeModel = new ImageResizeModel
                    {
                        ReSizedImage = ResizeImage(image.Height, original)
                    };
                    list.Add(imageResizeModel);
                }
                byte[] img = list.FirstOrDefault().ReSizedImage;
                return(img);
            }
            catch (Exception)
            {
                return(null);
            }
        }
Exemplo n.º 3
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="context"></param>
        public async Task InvokeAsync(HttpContext context)
        {
            await Task.FromResult(0);

            var options = this.options.Value;

            if (options.RequestConstrainAsync is not null)
            {
                if (!await options.RequestConstrainAsync.Invoke(context))
                {
                    return;
                }
            }

            var model = new ImageResizeModel {
                ImagePath = context.Request.Path
            };
            var imagePath = model.Resize(options)?.Replace(Path.DirectorySeparatorChar, '/');

            if (imagePath.IsNotNullOrEmpty())
            {
                context.Response.Redirect(imagePath);
            }
        }