public async Task <IActionResult> Index(FileUploadViewModel viewModel) { //This line compress the file and return the bytes array var tinyPngHelper = new TinyPngHelper(); var compressedImage = await tinyPngHelper.CompressImage(viewModel.FormFile); // Gzip Compress further var gzipCompressedImage = tinyPngHelper.GzipImage(compressedImage); return(View()); }
public void CompressImageTest() { var tinyPngHelper = new TinyPngHelper(); var formFile = GetIFormFileMock(); const string uncompressed = "iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAAEnQAABJ0Ad5mH3gAAAANSURBVBhXY/h57fF/AAkwA7IFNFSkAAAAAElFTkSuQmCC"; var uncompressedBytes = Convert.FromBase64String(uncompressed); var compressedBytes = tinyPngHelper.CompressImage(uncompressedBytes).Result; Assert.True(compressedBytes != null); Assert.True(compressedBytes.Length <= uncompressedBytes.Length); }