コード例 #1
0
        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());
        }
コード例 #2
0
        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);
        }