mapbox / pixelmatch

The smallest, simplest and fastest JavaScript pixel-level image comparison library
ISC License
6.15k stars 305 forks source link

[Feature Request] Returns not only diff count, but also diff details. #94

Closed fralonra closed 3 years ago

fralonra commented 3 years ago

Hi, thanks to this great project, my life becomes easier now.

However, I still seek for a new feature that seems handy to implement.

Right now the main function only returns the count of diff, but sometimes we also need to figure out where the two images are different and how they are different.

So can we add some additional info to the return, something like the following:

{
  diffCount: 12, // the diff count which is currently returned by the function
  pixels: [{ // an array of all different positions
    position: 123, // where the data is different
    colors: [78, 78, 78, 255] // here I list the color of the position on img2 as an example
  }]
}

Thanks for reply!

mourner commented 3 years ago

Can you describe how you would use that kind of array? Would it be enough to use the existing diff output combined with the diffMask: true option?

fralonra commented 3 years ago

Hi, diffMask doesn't feed my need. I just want the original data of the pixel where the two images are different.

For example, if the position (or the coordinate) and color of img2 on that pixel are given, we can draw this pixel directly on img1 and let it looks like img2.

mourner commented 3 years ago

@fralonra I still don't understand the use case here — if you need to draw differences from img2 on top of img1, why not just replace img1 with img2 directly? Exposing an API with an array of pixels and diffs seems cumbersome and not satisfying a common need.

fralonra commented 3 years ago

@mourner Yes, it's not a common need, but I still need it :P

If you think it's not suitable to add this feature to the lib, it's ok and I would like to close the issue and implement my own code for this.