pdf-visual-diff icon indicating copy to clipboard operation
pdf-visual-diff copied to clipboard

Feature request: ability to define masks that allow for varying thresholds

Open GrayedFox opened this issue 11 months ago • 2 comments

Background

Original idea found in comment here.

Always best to avoid phrasing things as an X/Y problem so going to expose the use case: we have sections of the PDFs we generate that contain signatures and in our test suite it's possible for this (and certain other areas like initials) to occasionally be a few pixels out based on the device and OS the signature or initials were drawn on.

Since our core product is producing legally compliant PDFs, we still want diffs to fail if even something as simple as a comma is missing, given that a comma can change the meaning of a sentence and we need to ensure our legal copy matches what we get from the lawyers exactly.

This feature would meet our need to maintain a 100% pixel match for the vast majority of the content on the PDF.

User Story

As a test engineer, I would like to be able to specify masks that allow for varied thresholds, so that I can reduce thresholds for specific sections of a PDF/PNG instead of the entire document.

Acceptance Criteria

  • test writers can specify a threshold-mask (or some other name) which marks a designated area as having a seperate threshold to that of the base one
  • when comparing the snapshots areas inside of a threshold-mask should use the specified threshold and not the global threshold

Nice to Haves

If a snapshot fails based on a pixel difference from inside of a threshold-mask it wouldbe nice to indicate this in some way.

Some ideas:

  • in the resulting diff based on the threshold-mask properties
  • in the resulting console output
  • programatically so that the test can act on it by adding a new signature for the comparison method that allows specifying a callback function so the returned result of the diff can either be a boolean OR a callback method that exposes more info through via an object passed into the callback function

Are you willing to work on this yourself?

Yes, ties in very well with our business needs, I'd need to go through the correct channels at work but would be happy to give this a go.

GrayedFox avatar Nov 28 '24 00:11 GrayedFox