/// <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; }
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); } }
/// <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); } }