Example #1
0
        private void CompressJpgImage(TemporaryFile tempFile)
        {
            var jpegOptimizer = new JpegOptimizer();

            if (chkQuality.Checked)
            {
                jpegOptimizer.Compress(tempFile, int.Parse(txtQuality.Text));
            }
            else
            {
                jpegOptimizer.Compress(tempFile);
            }
        }
                public void ShouldResultInSmallerFileWHenQualityIsSetTo40()
                {
                    using (TemporaryFile tempFile = new TemporaryFile(Files.ImageMagickJPG))
                    {
                        JpegOptimizer optimizer = new JpegOptimizer();
                        optimizer.Compress(tempFile);

                        IMagickImageInfo info = new MagickImageInfo(tempFile);
                        Assert.AreEqual(85, info.Quality);

                        File.Copy(Files.ImageMagickJPG, tempFile.FullName, true);

                        optimizer.Compress(tempFile, 40);

                        info = new MagickImageInfo(tempFile);
                        Assert.AreEqual(40, info.Quality);
                    }
                }
Example #3
0
                public void ShouldResultInSmallerFileWHenQualityIsSetTo40()
                {
                    using (var tempFile = new TemporaryFile(Files.ImageMagickJPG))
                    {
                        var optimizer = new JpegOptimizer();
                        optimizer.Compress(tempFile.FileInfo);

                        var info = new MagickImageInfo(tempFile.FileInfo);
                        Assert.Equal(85, info.Quality);

                        FileHelper.Copy(Files.ImageMagickJPG, tempFile.FullName);

                        optimizer.Compress(tempFile.FileInfo, 40);

                        info = new MagickImageInfo(tempFile.FileInfo);
                        Assert.Equal(40, info.Quality);
                    }
                }
        public void Test_Compress_Quality()
        {
            FileInfo tempFile = CreateTemporaryFile(Files.ImageMagickJPG);

            try
            {
                JpegOptimizer optimizer = new JpegOptimizer();
                optimizer.Compress(tempFile);

                IMagickImageInfo info = new MagickImageInfo(tempFile);
                Assert.AreEqual(85, info.Quality);

                File.Copy(Files.ImageMagickJPG, tempFile.FullName, true);

                optimizer.Compress(tempFile, 40);

                info = new MagickImageInfo(tempFile);
                Assert.AreEqual(40, info.Quality);
            }
            finally
            {
                tempFile.Delete();
            }
        }