4.1 KiB
4.1 KiB
Verify.ImageMagick
Extends Verify to allow verification of documents via Magick.NET.
See Milestones for release notes.
Converts documents pdfs to png for verification.
Contains comparers for png, jpg, bmp, and tiff.
NuGet package
https://nuget.org/packages/Verify.ImageMagick/
Usage
[ModuleInitializer]
public static void Init()
{
VerifyImageMagick.Initialize();
VerifyImageMagick.RegisterComparers(threshold: 0.05);
}
Initialize
registers the pdf to png converter and all comparers.
PDF converter
To register only the pdf to png converter:
VerifyImageMagick.RegisterPdfToPngConverter();
Verify a file
[Test]
public Task VerifyPdf() =>
VerifyFile("sample.pdf");
Verify a Stream
[Test]
public Task VerifyPdfStream()
{
var stream = new MemoryStream(File.ReadAllBytes("sample.pdf"));
return Verify(stream, "pdf");
}
Result
Samples.VerifyPdf#00.verified.png:
Image Comparers
The following will use ImageMagick to compare the images instead of the default binary comparison.
[Test]
public Task CompareImage() =>
VerifyFile("sample.jpg");
Register all comparers
All comparers can be registered:
VerifyImageMagick.RegisterComparers();
Override transparent background
For images with a transparent background, that background can be overridden:
[Test]
public Task BackgroundColor() =>
VerifyFile("transparent.png")
.ImageMagickBackground(MagickColors.Blue);
Open password-protected PDFs
For password-protected PDF, the password can be provided to allow verification:
[Test]
public Task PdfPassword() =>
VerifyFile("password.pdf")
.ImageMagickPdfPassword("password");
Icon
Swirl designed by Philipp Petzka from The Noun Project.