mapbox / pixelmatch

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

Image Unit8Array data length won't match #101

Closed MrBiscuit closed 2 years ago

MrBiscuit commented 2 years ago

Let's say the image is a 100x100 pixels pure black square PNG, and I type 100 for the width parameter and 100 for the height parameter, and it still throws 'Image data size does not match width/height.'

When I console.log the 100x100 pure black PNG Unit8Array.length, it gives 345 So then I typed Math.sqrt(Unit8Array.length/4) for width and height parameters and it works, however, adding a 10x10 red square inside (in the center) the 100x100 black square results in a Unit8Array.length of 378 instead of 345.

Screen Shot 2021-11-03 at 4 39 44 PM

Am I supposed to input sqrt((img1.length+img2.length)/2/4)? Even so, img2 won't have the same exact length as img1 and it will throw Image sizes do not match

mourner commented 2 years ago

Gosh. Can you at least take a look at the examples in the readme before opening issues? Pixelmatch accepts pixel data as input, so a 100x100 image will have exactly 40000 length, unless you forgot to decode your PNG.