An open API service indexing awesome lists of open source software.

https://github.com/verifytests/verify.imagemagick

Extends Verify to allow verification of documents via ImageMagick.NET.
https://github.com/verifytests/verify.imagemagick

Last synced: 2 months ago
JSON representation

Extends Verify to allow verification of documents via ImageMagick.NET.

Awesome Lists containing this project

README

          

# Verify.ImageMagick

[![Discussions](https://img.shields.io/badge/Verify-Discussions-yellow?svg=true&label=)](https://github.com/orgs/VerifyTests/discussions)
[![Build status](https://img.shields.io/appveyor/build/SimonCropp/Verify-ImageMagick)](https://ci.appveyor.com/project/SimonCropp/Verify-ImageMagick)
[![NuGet Status](https://img.shields.io/nuget/v/Verify.ImageMagick.svg)](https://www.nuget.org/packages/Verify.ImageMagick/)

Extends [Verify](https://github.com/VerifyTests/Verify) to allow verification of documents via [Magick.NET](https://github.com/dlemstra/Magick.NET).

**See [Milestones](../../milestones?state=closed) for release notes.**

Converts documents pdfs to png for verification.

Contains [comparers](https://github.com/VerifyTests/Verify/blob/master/docs/comparer.md) for png, jpg, bmp, and tiff.

## Sponsors

### Entity Framework Extensions

[Entity Framework Extensions](https://entityframework-extensions.net/?utm_source=simoncropp&utm_medium=Verify.ImageMagick) is a major sponsor and is proud to contribute to the development this project.

[![Entity Framework Extensions](https://raw.githubusercontent.com/VerifyTests/Verify.ImageMagick/refs/heads/main/docs/zzz.png)](https://entityframework-extensions.net/?utm_source=simoncropp&utm_medium=Verify.ImageMagick)

### Developed using JetBrains IDEs

[![JetBrains logo.](https://raw.githubusercontent.com/VerifyTests/Verify.ImageMagick/main/docs/jetbrains.png)](https://jb.gg/OpenSourceSupport)

## NuGet

* https://nuget.org/packages/Verify.ImageMagick

## Usage


```cs
[ModuleInitializer]
public static void Init()
{
VerifyImageMagick.Initialize();
VerifyImageMagick.RegisterComparers(threshold: 0.5);
}
```
snippet source | anchor

`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


```cs
[Test]
public Task VerifyPdf() =>
VerifyFile("sample.pdf");
```
snippet source | anchor

#### Verify a Stream


```cs
[Test]
public Task VerifyPdfStream()
{
var stream = new MemoryStream(File.ReadAllBytes("sample.pdf"));
return Verify(stream, "pdf");
}
```
snippet source | anchor

#### Result

[Samples.VerifyPdf#00.verified.png](/src/Tests/Samples.VerifyPdf#00.verified.png):

### Image Comparers

The following will use ImageMagick to compare the images instead of the default binary comparison.


```cs
[Test]
public Task CompareImage() =>
VerifyFile("sample.jpg");
```
snippet source | anchor

### Register all comparers

All comparers can be registered:

```
VerifyImageMagick.RegisterComparers();
```

### Override transparent background

For images with a transparent background, that background can be overridden:


```cs
[Test]
public Task BackgroundColor() =>
VerifyFile("transparent.png")
.ImageMagickBackground(MagickColors.Blue);
```
snippet source | anchor

### Open password-protected PDFs

For password-protected PDF, the password can be provided to allow verification:


```cs
[Test]
public Task PdfPassword() =>
VerifyFile("password.pdf")
.ImageMagickPdfPassword("password");
```
snippet source | anchor

## Icon

[Swirl](https://thenounproject.com/term/wizard/2744075/) designed by [Philipp Petzka](https://thenounproject.com/masteroficon) from [The Noun Project](https://thenounproject.com/).