looks-same
Advanced tools
Comparing version 4.1.0 to 5.0.0
@@ -1,2 +0,2 @@ | ||
// Type definitions for looks-same 4.0 | ||
// Type definitions for looks-same 5.0 | ||
// Project: https://github.com/gemini-testing/looks-same/releases | ||
@@ -7,5 +7,41 @@ // Definitions by: xcatliu <https://github.com/xcatliu> | ||
type LooksSameCallback = (error: Error | null, equal: boolean) => void; | ||
/** | ||
* diff bounds for not equal images | ||
*/ | ||
interface DiffBounds { | ||
/** | ||
* X-coordinate of diff upper left corner | ||
*/ | ||
left: number; | ||
/** | ||
* Y-coordinate of diff upper left corner | ||
*/ | ||
top: number; | ||
/** | ||
* X-coordinate of diff bottom right corner | ||
*/ | ||
right: number; | ||
/** | ||
* Y-coordinate of diff bottom right corner | ||
*/ | ||
bottom: number; | ||
} | ||
/** | ||
* The result obtained from the function. | ||
*/ | ||
interface LooksSameResult { | ||
/** | ||
* true if images are equal, false - otherwise | ||
*/ | ||
equal?: boolean; | ||
/** | ||
* diff bounds for not equal images | ||
*/ | ||
diffBounds?: DiffBounds; | ||
} | ||
type LooksSameCallback = (error: Error | null, result: LooksSameResult) => void; | ||
/** | ||
* The options passed to looksSame function | ||
@@ -47,2 +83,7 @@ */ | ||
antialiasingTolerance?: number; | ||
/** | ||
* Responsible for diff area which will be returned when comparing images. | ||
* Diff bounds will contain the whole diff if stopOnFirstFail is false and only first diff pixel - otherwise. | ||
*/ | ||
stopOnFirstFail?: boolean; | ||
} | ||
@@ -49,0 +90,0 @@ |
30
index.js
@@ -31,6 +31,3 @@ 'use strict'; | ||
const width = (right - left) + 1; | ||
const height = (bottom - top) + 1; | ||
return {left, top, width, height}; | ||
return {left, top, right, bottom}; | ||
}; | ||
@@ -151,2 +148,9 @@ | ||
const getMaxDiffBounds = (first, second) => ({ | ||
left: 0, | ||
top: 0, | ||
right: Math.max(first.width, second.width) - 1, | ||
bottom: Math.max(first.height, second.height) - 1 | ||
}); | ||
module.exports = exports = function looksSame(reference, image, opts, callback) { | ||
@@ -169,9 +173,12 @@ if (!callback) { | ||
if (first.width !== second.width || first.height !== second.height) { | ||
return process.nextTick(() => callback(null, false)); | ||
return process.nextTick(() => callback(null, {equal: false, diffBounds: getMaxDiffBounds(first, second)})); | ||
} | ||
const comparator = createComparator(first, second, opts); | ||
const {stopOnFirstFail} = opts; | ||
getDiffPixelsCoords(first, second, comparator, {stopOnFirstFail: true}, (result) => { | ||
callback(null, result.length === 0); | ||
getDiffPixelsCoords(first, second, comparator, {stopOnFirstFail}, (result) => { | ||
const diffBounds = getDiffArea(result); | ||
callback(null, {equal: result.length === 0, diffBounds}); | ||
}); | ||
@@ -198,8 +205,3 @@ }); | ||
if (first.width !== second.width || first.height !== second.height) { | ||
return process.nextTick(() => callback(null, { | ||
width: Math.max(first.width, second.width), | ||
height: Math.max(first.height, second.height), | ||
top: 0, | ||
left: 0 | ||
})); | ||
return process.nextTick(() => callback(null, getMaxDiffBounds(first, second))); | ||
} | ||
@@ -209,3 +211,3 @@ | ||
getDiffPixelsCoords(first, second, comparator, (result) => { | ||
getDiffPixelsCoords(first, second, comparator, opts, (result) => { | ||
if (!result.length) { | ||
@@ -212,0 +214,0 @@ return callback(null, null); |
{ | ||
"name": "looks-same", | ||
"version": "4.1.0", | ||
"version": "5.0.0", | ||
"description": "Pure node.js library for comparing PNG-images, taking into account human color perception.", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -15,4 +15,4 @@ # LooksSame | ||
looksSame('image1.png', 'image2.png', function(error, equal) { | ||
//equal will be true, if images looks the same | ||
looksSame('image1.png', 'image2.png', function(error, {equal}) { | ||
// equal will be true, if images looks the same | ||
}); | ||
@@ -27,3 +27,3 @@ ``` | ||
```javascript | ||
looksSame('image1.png', 'image2.png', {strict: true}, function(error, equal) { | ||
looksSame('image1.png', 'image2.png', {strict: true}, function(error, {equal}) { | ||
... | ||
@@ -37,3 +37,3 @@ }); | ||
```javascript | ||
looksSame('image1.png', 'image2.png', {tolerance: 5}, function(error, equal) { | ||
looksSame('image1.png', 'image2.png', {tolerance: 5}, function(error, {equal}) { | ||
... | ||
@@ -53,3 +53,3 @@ }); | ||
```javascript | ||
looksSame('image1.png', 'image2.png', {pixelRatio: 2}, function(error, equal) { | ||
looksSame('image1.png', 'image2.png', {pixelRatio: 2}, function(error, {equal}) { | ||
... | ||
@@ -65,3 +65,3 @@ }); | ||
```javascript | ||
looksSame('image1.png', 'image2.png', {ignoreCaret: true}, function(error, equal) { | ||
looksSame('image1.png', 'image2.png', {ignoreCaret: true}, function(error, {equal}) { | ||
... | ||
@@ -78,3 +78,3 @@ }); | ||
```javascript | ||
looksSame('image1.png', 'image2.png', {ignoreAntialiasing: true}, function(error, equal) { | ||
looksSame('image1.png', 'image2.png', {ignoreAntialiasing: true}, function(error, {equal}) { | ||
... | ||
@@ -90,3 +90,3 @@ }); | ||
```javascript | ||
looksSame('image1.png', 'image2.png', {ignoreAntialiasing: true, antialiasingTolerance: 3}, function(error, equal) { | ||
looksSame('image1.png', 'image2.png', {ignoreAntialiasing: true, antialiasingTolerance: 3}, function(error, {equal}) { | ||
... | ||
@@ -96,2 +96,14 @@ }); | ||
### Getting diff bounds | ||
Looksame returns information about diff bounds. It returns only first pixel if you passed `stopOnFirstFail` option with `true` value. The whole diff area would be returned if `stopOnFirstFail` option is not passed or it's passed with `false` value. | ||
```javascript | ||
looksSame('image1.png', 'image2.png', {stopOnFirstFail: false}, function(error, {equal, diffBounds}) { | ||
// { | ||
// equal: false, | ||
// diffBounds: {left: 10, top: 10, right: 20, bottom: 20} | ||
// } | ||
}); | ||
``` | ||
## Building diff image | ||
@@ -98,0 +110,0 @@ |
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
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
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
36633
816
143
1