public static async Task <ImageHolder> ResizeImageSave(Stream imgStream, int resizeMaxWidth = ResizeMaxWidthDefault) { try { using var limitStream = new LimitStream(imgStream, Limits.MaxImageStreamSize); using var mem = new MemoryStream(); await limitStream.CopyToAsync(mem); mem.Seek(0, SeekOrigin.Begin); return(ResizeImage(mem, resizeMaxWidth)); } catch (ImageFormatException) { Log.Debug("Dropping image because of unknown format"); throw Error.LocalStr("Dropping image because of unknown format"); // TODO } catch (EntityTooLargeException) { Log.Debug("Dropping image because too large"); throw Error.LocalStr("Dropping image because too large"); // TODO } }
public static R <Stream, LocalStr> ResizeImageSave(Stream imgStream, out string mime, int resizeMaxWidth = ResizeMaxWidthDefault) { mime = null; if (imgStream == null) { return(null); } try { using (var limitStream = new LimitStream(imgStream, Limits.MaxImageStreamSize)) return(ResizeImage(limitStream, out mime, resizeMaxWidth)); } catch (NotSupportedException) { Log.Debug("Dropping image because of unknown format"); return(new LocalStr("Dropping image because of unknown format")); // TODO } catch (EntityTooLargeException) { Log.Debug("Dropping image because too large"); return(new LocalStr("Dropping image because too large")); // TODO } }