protected virtual void OnImageUploaded(ImageUploadedEvent eventArgs) { if (eventArgs == null) { throw new ArgumentException("eventArgs"); } EventHub.Raise(eventArgs); }
protected async Task <AsyncOut <IImage> > ProcessImage(MediaFile file, Stream inStream) { var originalSize = Size.Empty; var format = _imageProcessor.Factory.FindFormatByExtension(file.Extension) ?? new UnsupportedImageFormat(file.MimeType, file.Extension); try { originalSize = ImageHeader.GetPixelSize(inStream, file.MimeType); } catch { } IImage outImage; if (format is UnsupportedImageFormat) { outImage = new ImageWrapper(inStream, originalSize, format); return(new AsyncOut <IImage>(true, outImage)); } var maxSize = _mediaSettings.MaximumImageSize; var query = new ProcessImageQuery(inStream) { Format = file.Extension, DisposeSource = true, ExecutePostProcessor = ImagePostProcessingEnabled, IsValidationMode = true }; if (originalSize.IsEmpty || (originalSize.Height <= maxSize && originalSize.Width <= maxSize)) { // Give subscribers the chance to (pre)-process var evt = new ImageUploadedEvent(query, originalSize); await _eventPublisher.PublishAsync(evt); outImage = evt.ResultImage ?? new ImageWrapper(inStream, originalSize, format); return(new AsyncOut <IImage>(true, outImage)); } query.MaxSize = maxSize; using (var result = await _imageProcessor.ProcessImageAsync(query, false)) { outImage = result.Image; return(new AsyncOut <IImage>(true, outImage)); } }