looks-same
Advanced tools
Comparing version 6.0.0 to 7.0.0
@@ -8,19 +8,19 @@ // Type definitions for looks-same 5.0 | ||
/** | ||
* diff bounds for not equal images | ||
* coordinate bounds | ||
*/ | ||
interface DiffBounds { | ||
interface CoordBounds { | ||
/** | ||
* X-coordinate of diff upper left corner | ||
* X-coordinate of upper left corner | ||
*/ | ||
left: number; | ||
/** | ||
* Y-coordinate of diff upper left corner | ||
* Y-coordinate of upper left corner | ||
*/ | ||
top: number; | ||
/** | ||
* X-coordinate of diff bottom right corner | ||
* X-coordinate of bottom right corner | ||
*/ | ||
right: number; | ||
/** | ||
* Y-coordinate of diff bottom right corner | ||
* Y-coordinate of bottom right corner | ||
*/ | ||
@@ -31,2 +31,16 @@ bottom: number; | ||
/** | ||
* bounded image | ||
*/ | ||
interface BoundedImage { | ||
/** | ||
* image path or buffer | ||
*/ | ||
source: string | Buffer; | ||
/** | ||
* bounding coordinates | ||
*/ | ||
boundingBox: CoordBounds; | ||
} | ||
/** | ||
* The result obtained from the function. | ||
@@ -42,3 +56,3 @@ */ | ||
*/ | ||
diffBounds?: DiffBounds; | ||
diffBounds?: CoordBounds; | ||
} | ||
@@ -99,9 +113,9 @@ | ||
/** | ||
* The baseline image path | ||
* The baseline image | ||
*/ | ||
reference: string; | ||
reference: string | Buffer | BoundedImage; | ||
/** | ||
* The current image path | ||
* The current image | ||
*/ | ||
current: string; | ||
current: string | Buffer | BoundedImage; | ||
/** | ||
@@ -164,15 +178,24 @@ * Color to highlight the differences | ||
* Compare two images with options | ||
* @param image1 The first image path | ||
* @param image2 The second image path | ||
* @param image1 The first image | ||
* @param image2 The second image | ||
* @param options The options passed to looksSame function | ||
* @param callback Call when finish compare | ||
*/ | ||
declare function looksSame(image1: string, image2: string, options: LooksSameOptions, callback: LooksSameCallback): void; | ||
declare function looksSame( | ||
image1: string | Buffer | BoundedImage, | ||
image2: string | Buffer | BoundedImage, | ||
options: LooksSameOptions, | ||
callback: LooksSameCallback | ||
): void; | ||
/** | ||
* Compare two images | ||
* @param image1 The first image path | ||
* @param image2 The second image path | ||
* @param image1 The first image | ||
* @param image2 The second image | ||
* @param callback Call when finish compare | ||
*/ | ||
declare function looksSame(image1: string, image2: string, callback: LooksSameCallback): void; | ||
declare function looksSame( | ||
image1: string | Buffer | BoundedImage, | ||
image2: string | Buffer | BoundedImage, | ||
callback: LooksSameCallback | ||
): void; | ||
@@ -179,0 +202,0 @@ // https://stackoverflow.com/questions/44058101/typescript-declare-third-party-modules |
52
index.js
@@ -11,7 +11,5 @@ 'use strict'; | ||
const utils = require('./lib/utils'); | ||
const readPair = utils.readPair; | ||
const getDiffPixelsCoords = utils.getDiffPixelsCoords; | ||
const {getDiffPixelsCoords} = utils; | ||
const {JND} = require('./lib/constants'); | ||
const JND = 2.3; // Just noticeable difference if ciede2000 >= JND then colors difference is noticeable by human eye | ||
const makeAntialiasingComparator = (comparator, png1, png2, opts) => { | ||
@@ -124,3 +122,3 @@ const antialiasingComparator = new AntialiasingComparator(comparator, png1, png2, opts); | ||
_.defaults(opts, { | ||
return _.defaults(opts, { | ||
ignoreCaret: true, | ||
@@ -132,10 +130,14 @@ ignoreAntialiasing: true, | ||
const getMaxDiffBounds = (first, second) => ({ | ||
left: 0, | ||
top: 0, | ||
right: Math.max(first.width, second.width) - 1, | ||
bottom: Math.max(first.height, second.height) - 1 | ||
}); | ||
const getMaxDiffBounds = (first, second) => { | ||
const {x: left, y: top} = first.getActualCoord(0, 0); | ||
module.exports = exports = function looksSame(reference, image, opts, callback) { | ||
return { | ||
left, | ||
top, | ||
right: left + Math.max(first.width, second.width) - 1, | ||
bottom: top + Math.max(first.height, second.height) - 1 | ||
}; | ||
}; | ||
module.exports = exports = function looksSame(image1, image2, opts, callback) { | ||
if (!callback) { | ||
@@ -146,5 +148,6 @@ callback = opts; | ||
prepareOpts(opts); | ||
opts = prepareOpts(opts); | ||
[image1, image2] = utils.formatImages(image1, image2); | ||
readPair(reference, image, (error, pair) => { | ||
utils.readPair(image1, image2, (error, pair) => { | ||
if (error) { | ||
@@ -154,5 +157,4 @@ return callback(error); | ||
const first = pair.first; | ||
const second = pair.second; | ||
const refImg = {size: {width: pair.first.width, height: pair.first.height}}; | ||
const {first, second} = pair; | ||
const refImg = {size: {width: first.width, height: first.height}}; | ||
const metaInfo = {refImg}; | ||
@@ -175,3 +177,3 @@ | ||
exports.getDiffArea = function(reference, image, opts, callback) { | ||
exports.getDiffArea = function(image1, image2, opts, callback) { | ||
if (!callback) { | ||
@@ -182,5 +184,6 @@ callback = opts; | ||
prepareOpts(opts); | ||
opts = prepareOpts(opts); | ||
[image1, image2] = utils.formatImages(image1, image2); | ||
readPair(reference, image, (error, pair) => { | ||
utils.readPair(image1, image2, (error, pair) => { | ||
if (error) { | ||
@@ -190,4 +193,3 @@ return callback(error); | ||
const first = pair.first; | ||
const second = pair.second; | ||
const {first, second} = pair; | ||
@@ -211,5 +213,7 @@ if (first.width !== second.width || first.height !== second.height) { | ||
exports.createDiff = function saveDiff(opts, callback) { | ||
prepareOpts(opts); | ||
opts = prepareOpts(opts); | ||
readPair(opts.reference, opts.current, (error, {first, second}) => { | ||
const [image1, image2] = utils.formatImages(opts.reference, opts.current); | ||
utils.readPair(image1, image2, (error, {first, second}) => { | ||
if (error) { | ||
@@ -216,0 +220,0 @@ return callback(error); |
'use strict'; | ||
const _ = require('lodash'); | ||
const png = require('./png'); | ||
const DiffArea = require('./diff-area'); | ||
const png = require('../lib/png'); | ||
const validators = require('./validators'); | ||
const readPair = (first, second, callback) => { | ||
exports.readPair = (first, second, callback) => { | ||
const src = {first, second}; | ||
@@ -14,6 +16,6 @@ const result = {first: null, second: null}; | ||
['first', 'second'].forEach((key) => { | ||
const source = src[key]; | ||
const {source, ...opts} = src[key]; | ||
const readFunc = Buffer.isBuffer(source) ? png.fromBuffer : png.fromFile; | ||
readFunc(source, (error, png) => { | ||
readFunc(source, opts, (error, png) => { | ||
if (failed) { | ||
@@ -38,3 +40,3 @@ return; | ||
const getDiffPixelsCoords = (png1, png2, predicate, opts, callback) => { | ||
exports.getDiffPixelsCoords = (png1, png2, predicate, opts, callback) => { | ||
if (!callback) { | ||
@@ -66,3 +68,4 @@ callback = opts; | ||
if (!result) { | ||
diffArea.update(x, y); | ||
const {x: actX, y: actY} = png1.getActualCoord(x, y); | ||
diffArea.update(actX, actY); | ||
@@ -74,2 +77,3 @@ if (stopOnFirstFail) { | ||
} | ||
y++; | ||
@@ -88,5 +92,8 @@ | ||
module.exports = { | ||
readPair, | ||
getDiffPixelsCoords | ||
exports.formatImages = (img1, img2) => { | ||
validators.validateImages(img1, img2); | ||
return [img1, img2].map((i) => { | ||
return _.isObject(i) && !Buffer.isBuffer(i) ? i : {source: i, boundingBox: null}; | ||
}); | ||
}; |
{ | ||
"name": "looks-same", | ||
"version": "6.0.0", | ||
"version": "7.0.0", | ||
"description": "Pure node.js library for comparing PNG-images, taking into account human color perception.", | ||
@@ -27,2 +27,3 @@ "main": "index.js", | ||
"sinon": "^6.1.5", | ||
"sinon-chai": "^3.3.0", | ||
"temp": "^0.8.3" | ||
@@ -37,3 +38,3 @@ }, | ||
"engines": { | ||
"node": ">= 6.0.0" | ||
"node": ">= 8.0.0" | ||
}, | ||
@@ -40,0 +41,0 @@ "author": "Sergey Tatarintsev <sevinf@yandex-team.ru> (https://github.com/SevInf)", |
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
39896
22
899
11
2