public void ShouldReadFileNameWithPixelStorageSettings() { var pixelStorageSettings = new PixelStorageSettings(1, 1, StorageType.Int32, "R"); var bytes = BitConverter.GetBytes(uint.MaxValue); using (var temporyFile = new TemporaryFile(bytes)) { var fileName = temporyFile.FullName; MagickFactory factory = new MagickFactory(); using (IMagickImage image = factory.CreateImage(fileName, pixelStorageSettings)) { Assert.AreEqual(1, image.Width); Assert.AreEqual(1, image.Height); ColorAssert.AreEqual(MagickColors.White, image, 0, 0); } } }
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); } }
public void ShouldReadFileInfoWithPixelStorageSettings() { var pixelStorageSettings = new PixelStorageSettings(1, 1, StorageType.Quantum, "R"); var bytes = BitConverter.GetBytes(Quantum.Max); using (var temporyFile = new TemporaryFile(bytes)) { FileInfo file = temporyFile; MagickFactory factory = new MagickFactory(); using (IMagickImage image = factory.CreateImage(file, pixelStorageSettings)) { Assert.AreEqual(1, image.Width); Assert.AreEqual(1, image.Height); ColorAssert.AreEqual(MagickColors.White, image, 0, 0); } } }
public void Compress_WithQualitySetTo40_FileIsSmallerThanNormalCompression() { 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); } }
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 async Task ShouldReadFileInfo() { var settings = new PixelReadSettings(1, 1, StorageType.Float, "R"); var bytes = BitConverter.GetBytes(1.0F); using (var temporyFile = new TemporaryFile(bytes)) { using (var image = new MagickImage()) { await image.ReadPixelsAsync(temporyFile.FileInfo, settings); Assert.Equal(1, image.Width); Assert.Equal(1, image.Height); ColorAssert.Equal(MagickColors.White, image, 0, 0); } } }
public void ShouldReadFileInfo() { var settings = new PixelReadSettings(1, 1, StorageType.Float, "R"); var bytes = BitConverter.GetBytes(1.0F); using (var temporyFile = new TemporaryFile(bytes)) { FileInfo file = temporyFile; using (var image = new MagickImage()) { image.ReadPixels(file, settings); Assert.AreEqual(1, image.Width); Assert.AreEqual(1, image.Height); ColorAssert.AreEqual(MagickColors.White, image, 0, 0); } } }
public void ShouldReadFileName() { var settings = new PixelReadSettings(1, 1, StorageType.Short, "R"); var bytes = BitConverter.GetBytes(ushort.MaxValue); using (var temporyFile = new TemporaryFile(bytes)) { var fileName = temporyFile.FullName; using (IMagickImage image = new MagickImage()) { image.ReadPixels(fileName, settings); Assert.AreEqual(1, image.Width); Assert.AreEqual(1, image.Height); ColorAssert.AreEqual(MagickColors.White, image, 0, 0); } } }
public void ShouldBeAbleToReadBmp3Format() { using (TemporaryFile file = new TemporaryFile(Files.MagickNETIconPNG)) { using (IMagickImage image = new MagickImage(file)) { image.Write(file, MagickFormat.Bmp3); } var settings = new MagickReadSettings() { Format = MagickFormat.Bmp3, }; using (IMagickImage image = new MagickImage(file, settings)) { Assert.AreEqual(MagickFormat.Bmp3, image.Format); } } }
public void ShouldBeAbleToReadBmp3Format() { using (var file = new TemporaryFile(Files.MagickNETIconPNG)) { using (var image = new MagickImage(file.FileInfo)) { image.Write(file.FileInfo, MagickFormat.Bmp3); } var settings = new MagickReadSettings { Format = MagickFormat.Bmp3, }; using (var image = new MagickImage(file.FileInfo, settings)) { Assert.Equal(MagickFormat.Bmp3, image.Format); } } }
public void ShouldThrowExceptionWhenInitializedWithCustomPolicyThatDisablesReadingPalmFiles() { using (var tempFile = new TemporaryFile("test.palm")) { using (var fs = tempFile.OpenWrite()) { var bytes = new byte[4] { 0, 0, 0, 0 }; fs.Write(bytes, 0, bytes.Length); } Assert.Throws <MagickPolicyErrorException>(() => { using (var image = new MagickImage(tempFile)) { } }); } }
public void ShouldUseTheFileExtension() { var readSettings = new MagickReadSettings() { Format = MagickFormat.Png, }; using (IMagickImage input = new MagickImage(Files.CirclePNG, readSettings)) { using (var tempFile = new TemporaryFile(".jpg")) { input.Write(tempFile); using (IMagickImage output = new MagickImage(tempFile)) { Assert.AreEqual(MagickFormat.Jpeg, output.Format); } } } }
public void ShouldCauseAnExceptionWhenThePalmCoderIsDisabled() { using (var tempFile = new TemporaryFile("test.palm")) { using (var fs = tempFile.FileInfo.OpenWrite()) { var bytes = new byte[4] { 0, 0, 0, 0 }; fs.Write(bytes, 0, bytes.Length); } Assert.Throws <MagickPolicyErrorException>(() => { using (var image = new MagickImage(tempFile.FileInfo)) { } }); } }
public async Task ShouldUseTheFileExtension() { var readSettings = new MagickReadSettings { Format = MagickFormat.Png, }; using (var input = new MagickImageCollection(Files.CirclePNG, readSettings)) { using (var tempFile = new TemporaryFile(".jpg")) { await input.WriteAsync(tempFile.FileInfo); using (var output = new MagickImageCollection(tempFile.FileInfo)) { Assert.Equal(MagickFormat.Jpeg, output[0].Format); } } } }
public void InitializedWithCustomPolicy_ReadPalmFile_ThrowsException() { using (TemporaryFile tempFile = new TemporaryFile("test.palm")) { using (FileStream fs = tempFile.OpenWrite()) { byte[] bytes = new byte[4] { 255, 255, 255, 255 }; fs.Write(bytes, 0, bytes.Length); } ExceptionAssert.Throws <MagickPolicyErrorException>(() => { using (MagickImage image = new MagickImage(tempFile)) { } }); } }
public void ShouldUseTheSpecifiedFormat() { using (var input = new MagickImage(Files.CirclePNG)) { using (var tempfile = new TemporaryFile("foobar")) { var defines = new JpegWriteDefines { DctMethod = JpegDctMethod.Fast, }; input.Write(tempfile.FullName, defines); Assert.Equal(MagickFormat.Png, input.Format); using (var output = new MagickImage(tempfile.FullName)) { Assert.Equal(MagickFormat.Jpeg, output.Format); } } } }
public void ShouldDisableAlphaChannelWhenPossible() { using (TemporaryFile tempFile = new TemporaryFile("no-alpha.png")) { using (var image = new MagickImage(Files.MagickNETIconPNG)) { Assert.IsTrue(image.HasAlpha); image.ColorAlpha(new MagickColor("yellow")); image.HasAlpha = true; image.Write(tempFile); image.Read(tempFile); Assert.IsTrue(image.HasAlpha); Optimizer.LosslessCompress(tempFile); image.Read(tempFile); Assert.IsFalse(image.HasAlpha); } } }
protected long AssertCompress(string fileName, bool resultIsSmaller, Action <FileInfo> action) { using (TemporaryFile tempFile = new TemporaryFile(fileName)) { long before = tempFile.Length; action(tempFile); long after = tempFile.Length; if (resultIsSmaller) { Assert.IsTrue(after < before, "{0} is not smaller than {1}", after, before); } else { Assert.AreEqual(before, after); } return(after); } }
public void LosslessCompress_ShouldPreserveTheColorProfile() { using (MagickImage image = new MagickImage()) { image.Ping(Files.PictureJPG); Assert.IsNotNull(image.GetColorProfile()); } using (TemporaryFile tempFile = new TemporaryFile(Files.PictureJPG)) { var result = Optimizer.LosslessCompress(tempFile); Assert.IsTrue(result); using (MagickImage image = new MagickImage()) { image.Ping(Files.PictureJPG); Assert.IsNotNull(image.GetColorProfile()); } } }
public void ShouldPreserveTheExifProfile() { using (var image = new MagickImage()) { image.Ping(Files.PictureJPG); Assert.NotNull(image.GetExifProfile()); } using (TemporaryFile tempFile = new TemporaryFile(Files.PictureJPG)) { var result = Optimizer.LosslessCompress(tempFile); Assert.True(result); using (var image = new MagickImage()) { image.Ping(tempFile); Assert.NotNull(image.GetExifProfile()); } } }
public void Test_ProcessRequest() { using (TemporaryFile file = new TemporaryFile("image.jpg")) { string tempFile = file.FullName; using (IMagickImage image = new MagickImage("logo:")) { image.Write(tempFile); } File.SetLastWriteTimeUtc(tempFile, new DateTime(2001, 1, 1)); IImageData imageData = new FileImageData(tempFile, JpgFormatInfo); Test_ProcessRequest(imageData); File.SetLastWriteTimeUtc(tempFile, new DateTime(2001, 1, 1)); TestStreamUrlResolver resolver = new TestStreamUrlResolver(tempFile); imageData = new StreamImageData(resolver, JpgFormatInfo); Test_ProcessRequest(imageData); } }
public void ShouldPreserveTheColorProfile() { using (var image = new MagickImage()) { image.Ping(Files.PictureJPG); Assert.NotNull(image.GetColorProfile()); } using (var tempFile = new TemporaryFile(Files.PictureJPG)) { var result = Optimizer.Compress(tempFile.FileInfo); Assert.True(result); using (var image = new MagickImage()) { image.Ping(tempFile.FileInfo); Assert.NotNull(image.GetColorProfile()); } } }
public void Test_RemoveAlpha() { using (TemporaryFile tempFile = new TemporaryFile("no-alpha.png")) { using (IMagickImage image = new MagickImage(Files.MagickNETIconPNG)) { Assert.IsTrue(image.HasAlpha); image.ColorAlpha(new MagickColor("yellow")); image.HasAlpha = true; image.Write(tempFile); image.Read(tempFile); Assert.IsTrue(image.HasAlpha); PngOptimizer optimizer = new PngOptimizer(); optimizer.LosslessCompress(tempFile); image.Read(tempFile); Assert.IsFalse(image.HasAlpha); } } }
public async Task ShouldUseTheSpecifiedFormat() { using (var input = new MagickImage(Files.CirclePNG)) { using (var tempfile = new TemporaryFile("foobar")) { var defines = new JpegWriteDefines { DctMethod = JpegDctMethod.Fast, }; await input.WriteAsync(tempfile.FileInfo, defines); Assert.Equal(MagickFormat.Png, input.Format); using (var output = new MagickImage()) { await output.ReadAsync(tempfile.FileInfo); Assert.Equal(MagickFormat.Jpeg, output.Format); } } } }
protected long AssertCompress(string fileName, bool resultIsSmaller, Func <FileInfo, bool> action) { using (var tempFile = new TemporaryFile(fileName)) { var before = tempFile.Length; var result = action(tempFile); var after = tempFile.Length; Assert.Equal(resultIsSmaller, result); if (resultIsSmaller) { Assert.True(after < before); } else { Assert.Equal(before, after); } return(after); } }
public void ShouldUseTheSpecifiedFormat() { using (var input = new MagickImageCollection(Files.CirclePNG)) { using (var tempfile = new TemporaryFile("foobar")) { var defines = new TiffWriteDefines() { Endian = Endian.MSB, }; input.Write(tempfile.FullName, MagickFormat.Tiff); Assert.Equal(MagickFormat.Png, input[0].Format); using (var output = new MagickImageCollection()) { output.Read(tempfile.FullName); Assert.Single(output); Assert.Equal(MagickFormat.Tiff, output[0].Format); } } } }