Exemple #1
0
        async void StandardInputTest()
        {
            var opts = new Options {
                MaxQuality      = 72,
                StripProperties = StripProperty.All
            };

            var jo = new JpegOptim(opts);

            var f = new FileStream(Files[0], FileMode.Open, FileAccess.Read, FileShare.Read);

            var result = await jo.RunAsync(f);

            Assert.NotNull(result);
            Assert.NotNull(result.OutputStream);
            Assert.Equal("stdin", result.SourceFile);
            Assert.Equal(91324, result.OptimizedSize);

            /*
             * var fs = new FileStream("stream_test.jpg", FileMode.Create);
             * result.OutputStream.CopyTo(fs);
             * await fs.FlushAsync();
             * fs.Close();
             */
        }
Exemple #2
0
        public async void CanReportForManyFiles()
        {
            var opts = new Options {
                NoAction = true
            };

            var jo     = new JpegOptim(opts);
            var result = await jo.RunAsync(Files.ToArray());

            Assert.NotNull(result);
            Assert.InRange(result.Count, Files.Count, Files.Count);
        }
Exemple #3
0
        public async void CanProcessToNewDirectory()
        {
            var dir  = "can_process_to_new_dir";
            var opts = new Options {
                DestinationFolder            = dir,
                OverwriteInDestinationFolder = true, // we use the same directory multiple times, must allow overwriting
                MaxQuality = 72                      // ensure files will be optimized
            };

            Directory.CreateDirectory(dir);

            var jo     = new JpegOptim(opts);
            var result = await jo.RunAsync(Files[0]);

            Assert.NotNull(result);
            Assert.True(result.Success);
            Assert.True(result.WasOptimized);
            Assert.True(File.Exists(Path.Combine(dir, Files[0])));

            var result2 = await jo.RunAsync(Files.ToArray());

            Assert.NotNull(result);

            foreach (var res in result2)
            {
                if (res.Success)
                {
                    if (res.WasOptimized)
                    {
                        Assert.True(File.Exists(Path.Combine(dir, res.SourceFile)));
                    }
                    else
                    {
                        Assert.False(File.Exists(Path.Combine(dir, res.SourceFile)));
                    }
                }
            }
        }
Exemple #4
0
        NJpegOptim.Result ExecuteJpegOptimAsync(string srcPath)
        {
            var opts = new NJpegOptim.Options {
                StripProperties = StripProperty.All,
                ProgressiveMode = ProgressiveMode.ForceProgressive,
                MaxQuality      = 72,
                OutputToStream  = true
            };

            var jo = new JpegOptim(opts);

            // ideally wouldn't block here but am being lazy
            return(jo.RunAsync(srcPath).Result);
        }
Exemple #5
0
        public async void CanReportOptimizationForSingleFile()
        {
            var opts = new Options {
                NoAction = true
            };

            var jo     = new JpegOptim(opts);
            var result = await jo.RunAsync(Files[0]);

            Assert.NotNull(result);
            Assert.True(result.Success);
            Assert.Equal("banner_lg.jpg", result.SourceFile);
            Assert.Equal("2160x600", result.Resolution);
            Assert.Equal("24bit", result.ColorDepth);
            Assert.Equal("P", result.NormalOrProgressive);
            Assert.Equal(139591, result.SourceSize);
            Assert.Equal(139591, result.OptimizedSize);
            Assert.Equal(0, result.PercentImprovement);
            Assert.False(result.WasOptimized);
        }