Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add option to prevent aliasing of pngs #80

Closed
GrayedFox opened this issue Oct 30, 2024 · 4 comments
Closed

add option to prevent aliasing of pngs #80

GrayedFox opened this issue Oct 30, 2024 · 4 comments

Comments

@GrayedFox
Copy link

GrayedFox commented Oct 30, 2024

One of the annoying challenges with PNG diffs is the fact that the host OS has different built in aliasing of images and text.

Going from PDF to .png mostly solves that for font since the diff is based on an image, but embedded logos on a PDF (I think?) picks up OS aliasing resulting in marginal diffs, will grab a screenshot next time it happens - I have a suspicion this is happening during the jimp scaling process.

I could be wrong, the aliasing might be happening on the OS side at the moment of the logo being uploaded, in which case this approach might not work.

This issue seems to surface a way of scaling a PNG without anti-aliasing - this is a bit over my head - but if it's possible to add an option for pdf-visual-diff to output PNGs that have platform agnostic aliasing (or no aliasing at all) this would save me quite some work, mid term plan is I will eventually run the playwright specs inside a docker container to ensure developers have uniform test runs and results and go from there.

TLDR: see if it's possible for pdf-visual-diff to output PNGs that bypass or workaround OS aliasing.

@moshensky
Copy link
Owner

Scaling is handled by the pdfjs when it renders the pdf to a canvas. A quick glance over pdfjs options was not enough to figure out if it is possible to disable anti-aliasing.

Nevertheless there are a couple of available options that you could try that come to my mind:

  • Try using tolerance option, but be careful to test that it won't tolerate unwanted changes;
  • Use Dpi.Low for the default PDF viewport size at 72 DPI. At this setting, one PDF point corresponds to one pixel;

@GrayedFox
Copy link
Author

Apologies for delayed response, specifying Dpi.low resolved the vast majority of the issues we had when running specs on Windows vs MacOS and Ubuntu inside WSL.

Currently experimenting with lowering the threshold for the few other minor things, this might be best asked inside it's own thread but am I correct in assuming that the threshold difference applies to the entire PNG file?

Might be out of scope of this nifty tool but I was thinking about whether a cool feature might be adding a new kind of mask that, rather than being a opaque rectangle, specifies an area that allows for a higher threshold tolerance 🤔

@moshensky
Copy link
Owner

Might be out of scope of this nifty tool but I was thinking about whether a cool feature might be adding a new kind of mask that, rather than being a opaque rectangle, specifies an area that allows for a higher threshold tolerance 🤔

That sounds doable. We already have the latest image of the PDF and the snapshot. We would need to take portions of those images and compare them using a different threshold.
Shouldn't take that much time, but still my time budget is a bit limited right now.
How about you take this to a new feature so that it could be tracked separately?

@GrayedFox
Copy link
Author

Will close this issue since most of the aliasing issues we ran into we could influence from the application code side of things and the DPI setting was the main thing in getting more closely alignedsnapshots. My spidey sense tells me trying to do that while snapshot testing might be too far down the production line to be effective - cheers for the tips!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants