resemblejs
Advanced tools
Comparing version 3.0.2 to 3.1.0
{ | ||
"name": "resemblejs", | ||
"version": "3.0.2", | ||
"version": "3.1.0", | ||
"description": "Image analysis and comparison with HTML5", | ||
@@ -26,4 +26,5 @@ "main": "resemble.js", | ||
"test": "jest nodejs-tests", | ||
"test-codacy-coverage": "jest nodejs-tests --coverage && cat ./coverage/lcov.info | codacy-coverage", | ||
"test-watch": "jest --watch nodejs-tests", | ||
"test:codacy-coverage": "jest nodejs-tests --coverage && cat ./coverage/lcov.info | codacy-coverage", | ||
"test:watch": "jest --watch nodejs-tests", | ||
"test:debug": "node --inspect node_modules/jest/bin/jest --watch --runInBand nodejs-tests", | ||
"lint": "eslint **/*.js --fix" | ||
@@ -50,9 +51,9 @@ }, | ||
"eslint-config-prettier": "^2.9.0", | ||
"eslint-plugin-import": "^2.12.0", | ||
"eslint-plugin-import": "^2.16.0", | ||
"eslint-plugin-prettier": "^2.6.0", | ||
"husky": "^1.2.0", | ||
"jest": "^23.6.0", | ||
"jest-cli": "^23.6.0", | ||
"lint-staged": "^8.1.0", | ||
"prettier": "^1.13.5" | ||
"husky": "^1.3.1", | ||
"jest": "^24.5.0", | ||
"jest-cli": "^24.5.0", | ||
"lint-staged": "^8.1.5", | ||
"prettier": "^1.16.4" | ||
}, | ||
@@ -59,0 +60,0 @@ "jest": { |
@@ -6,2 +6,3 @@ <h1 align="center"><img src="https://raw.github.com/rsmbl/Resemble.js/master/demoassets/resemble.png" alt="Resemble.js" width="256"/></h1> | ||
<a href="https://www.codacy.com/app/jamescryer/Resemble.js?utm_source=github.com&utm_medium=referral&utm_content=rsmbl/Resemble.js&utm_campaign=Badge_Grade"><img alt="Code Health" src="https://api.codacy.com/project/badge/Grade/1e0972581406417e9914bc58f57704b3" /></a> | ||
<a href="https://www.codacy.com/app/jamescryer/Resemble.js?utm_source=github.com&utm_medium=referral&utm_content=rsmbl/Resemble.js&utm_campaign=Badge_Coverage"><img alt="Coverage" src="https://api.codacy.com/project/badge/Coverage/9223d8d37c99428c8c06b889470327a5" /></a> | ||
<a href="https://opensource.org/licenses/MIT"><img alt="Build Status" src="https://img.shields.io/badge/License-MIT-yellow.svg" /></a> | ||
@@ -97,27 +98,31 @@ <a href="https://www.npmjs.com/package/resemblejs"><img alt="NPM Downloads" src="https://img.shields.io/npm/dm/resemblejs.svg" /></a> | ||
```javascript | ||
resemble.outputSettings({ | ||
boundingBox: { | ||
left: 100, | ||
top: 200, | ||
right: 200, | ||
bottom: 600 | ||
} | ||
}); | ||
// .repaint(); | ||
const box = { | ||
left: 100, | ||
top: 200, | ||
right: 200, | ||
bottom: 600 | ||
}; | ||
resemble.outputSettings({ boundingBox: box }); | ||
``` | ||
```javascript | ||
resemble.outputSettings({ boundingBoxes: [box1, box2] }); | ||
``` | ||
You can also exclude part of the image from comparison, by specifying the excluded area in pixels from the top left: | ||
```javascript | ||
resemble.outputSettings({ | ||
ignoredBox: { | ||
left: 100, | ||
top: 200, | ||
right: 200, | ||
bottom: 600 | ||
} | ||
}); | ||
// .repaint(); | ||
const box = { | ||
left: 100, | ||
top: 200, | ||
right: 200, | ||
bottom: 600 | ||
}; | ||
resemble.outputSettings({ ignoredBox: box }); | ||
``` | ||
```javascript | ||
resemble.outputSettings({ ignoredBoxes: [box1, box2] }); | ||
``` | ||
By default, the comparison algorithm skips pixels when the image width or height is larger than 1200 pixels. This is there to mitigate performance issues. | ||
@@ -146,3 +151,9 @@ | ||
function getDiff() { | ||
const options = {}; | ||
const options = { | ||
// stop comparing once determined to be > 5% non-matching; this will | ||
// also enable compare-only mode and no output image will be rendered; | ||
// the combination of these results in a significant speed-up in batch processing | ||
misMatchThreshold: 5 | ||
}; | ||
// The parameters can be Node Buffers | ||
@@ -149,0 +160,0 @@ // data is the same as usual with an additional getBuffer() function |
142
resemble.js
@@ -112,4 +112,4 @@ /* | ||
var errorType; | ||
var boundingBox; | ||
var ignoredBox; | ||
var boundingBoxes; | ||
var ignoredBoxes; | ||
var largeImageThreshold = 1200; | ||
@@ -134,2 +134,4 @@ var useCrossOrigin = true; | ||
var scaleToSameSize = false; | ||
var compareOnly = false; | ||
var returnEarlyThreshold; | ||
@@ -155,18 +157,42 @@ function colorsDistance(c1, c2) { | ||
function withinComparedArea(x, y, width, height) { | ||
var isIncluded = true; | ||
var isIncluded = true, | ||
i, | ||
boundingBox, | ||
ignoredBox, | ||
selected, | ||
ignored; | ||
if ( | ||
boundingBox !== undefined && | ||
!withinBoundingBox(x, y, width, height, boundingBox) | ||
) { | ||
isIncluded = false; | ||
if (boundingBoxes instanceof Array) { | ||
selected = false; | ||
for (i = 0; i < boundingBoxes.length; i++) { | ||
boundingBox = boundingBoxes[i]; | ||
if (withinBoundingBox(x, y, width, height, boundingBox)) { | ||
selected = true; | ||
break; | ||
} | ||
} | ||
} | ||
if (ignoredBoxes instanceof Array) { | ||
ignored = true; | ||
for (i = 0; i < ignoredBoxes.length; i++) { | ||
ignoredBox = ignoredBoxes[i]; | ||
if (withinBoundingBox(x, y, width, height, ignoredBox)) { | ||
ignored = false; | ||
break; | ||
} | ||
} | ||
} | ||
if ( | ||
ignoredBox !== undefined && | ||
withinBoundingBox(x, y, width, height, ignoredBox) | ||
) { | ||
if (selected === undefined && ignored === undefined) { | ||
return true; | ||
} | ||
if (selected === false && ignored === true) { | ||
return false; | ||
} | ||
if (selected === true || ignored === true) { | ||
isIncluded = true; | ||
} | ||
if (selected === false || ignored === false) { | ||
isIncluded = false; | ||
} | ||
return isIncluded; | ||
@@ -534,11 +560,17 @@ } | ||
function analyseImages(img1, img2, width, height) { | ||
var hiddenCanvas = createCanvas(width, height); | ||
var data1 = img1.data; | ||
var data2 = img2.data; | ||
var hiddenCanvas; | ||
var context; | ||
var imgd; | ||
var pix; | ||
var context = hiddenCanvas.getContext("2d"); | ||
var imgd = context.createImageData(width, height); | ||
var pix = imgd.data; | ||
if (!compareOnly) { | ||
hiddenCanvas = createCanvas(width, height); | ||
context = hiddenCanvas.getContext("2d"); | ||
imgd = context.createImageData(width, height); | ||
pix = imgd.data; | ||
} | ||
var mismatchCount = 0; | ||
@@ -573,3 +605,9 @@ var diffBounds = { | ||
var skipTheRest = false; | ||
loop(width, height, function(horizontalPos, verticalPos) { | ||
if (skipTheRest) { | ||
return; | ||
} | ||
if (skip) { | ||
@@ -608,5 +646,10 @@ // only skip if the image isn't small | ||
) { | ||
copyGrayScalePixel(pix, offset, pixel2); | ||
if (!compareOnly) { | ||
copyGrayScalePixel(pix, offset, pixel2); | ||
} | ||
} else { | ||
errorPixel(pix, offset, pixel1, pixel2); | ||
if (!compareOnly) { | ||
errorPixel(pix, offset, pixel1, pixel2); | ||
} | ||
mismatchCount++; | ||
@@ -619,3 +662,5 @@ updateBounds(horizontalPos, verticalPos); | ||
if (isRGBSimilar(pixel1, pixel2) || !isWithinComparedArea) { | ||
copyPixel(pix, offset, pixel1); | ||
if (!compareOnly) { | ||
copyPixel(pix, offset, pixel1); | ||
} | ||
} else if ( | ||
@@ -646,5 +691,10 @@ ignoreAntialiasing && | ||
) { | ||
copyGrayScalePixel(pix, offset, pixel2); | ||
if (!compareOnly) { | ||
copyGrayScalePixel(pix, offset, pixel2); | ||
} | ||
} else { | ||
errorPixel(pix, offset, pixel1, pixel2); | ||
if (!compareOnly) { | ||
errorPixel(pix, offset, pixel1, pixel2); | ||
} | ||
mismatchCount++; | ||
@@ -654,6 +704,18 @@ updateBounds(horizontalPos, verticalPos); | ||
} else { | ||
errorPixel(pix, offset, pixel1, pixel2); | ||
if (!compareOnly) { | ||
errorPixel(pix, offset, pixel1, pixel2); | ||
} | ||
mismatchCount++; | ||
updateBounds(horizontalPos, verticalPos); | ||
} | ||
if (compareOnly) { | ||
var currentMisMatchPercent = | ||
(mismatchCount / (height * width)) * 100; | ||
if (currentMisMatchPercent > returnEarlyThreshold) { | ||
skipTheRest = true; | ||
} | ||
} | ||
}); | ||
@@ -668,2 +730,8 @@ | ||
data.getImageDataUrl = function(text) { | ||
if (compareOnly) { | ||
throw Error( | ||
"No diff image available - ran in compareOnly mode" | ||
); | ||
} | ||
var barHeight = 0; | ||
@@ -680,3 +748,3 @@ | ||
if (hiddenCanvas.toBuffer) { | ||
if (!compareOnly && hiddenCanvas.toBuffer) { | ||
data.getBuffer = function(includeOriginal) { | ||
@@ -777,8 +845,16 @@ if (includeOriginal) { | ||
if (options.boundingBox !== undefined) { | ||
boundingBox = options.boundingBox; | ||
boundingBoxes = [options.boundingBox]; | ||
} | ||
if (options.ignoredBox !== undefined) { | ||
ignoredBox = options.ignoredBox; | ||
ignoredBoxes = [options.ignoredBox]; | ||
} | ||
if (options.boundingBoxes !== undefined) { | ||
boundingBoxes = options.boundingBoxes; | ||
} | ||
if (options.ignoredBoxes !== undefined) { | ||
ignoredBoxes = options.ignoredBoxes; | ||
} | ||
} | ||
@@ -852,2 +928,9 @@ | ||
var self = { | ||
setReturnEarlyThreshold: function(threshold) { | ||
if (threshold) { | ||
compareOnly = true; | ||
returnEarlyThreshold = threshold; | ||
} | ||
return self; | ||
}, | ||
scaleToSameSize: function() { | ||
@@ -987,2 +1070,3 @@ scaleToSameSize = true; | ||
}; | ||
return rootSelf; | ||
@@ -1042,2 +1126,6 @@ }; | ||
if (opt.returnEarlyThreshold) { | ||
compare.setReturnEarlyThreshold(opt.returnEarlyThreshold); | ||
} | ||
if (opt.scaleToSameSize) { | ||
@@ -1044,0 +1132,0 @@ compare.scaleToSameSize(); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
50458
985
244
10