Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

looks-same

Package Overview
Dependencies
Maintainers
6
Versions
42
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

looks-same - npm Package Compare versions

Comparing version 7.0.0 to 7.1.0

lib/diff-clusters/clusters-joiner.js

12

index.d.ts

@@ -55,2 +55,6 @@ // Type definitions for looks-same 5.0

diffBounds?: CoordBounds;
/**
* diff clusters for not equal images
*/
diffClusters?: CoordBounds[];
}

@@ -104,2 +108,10 @@

stopOnFirstFail?: boolean;
/**
* Responsible for diff bounds clustering
*/
shouldCluster?: boolean;
/**
* Radius for every diff cluster
*/
clustersSize?: number;
}

@@ -106,0 +118,0 @@

14

index.js

@@ -162,8 +162,8 @@ 'use strict';

const comparator = createComparator(first, second, opts);
const {stopOnFirstFail} = opts;
const {stopOnFirstFail, shouldCluster, clustersSize} = opts;
getDiffPixelsCoords(first, second, comparator, {stopOnFirstFail}, (result) => {
const diffBounds = result.area;
getDiffPixelsCoords(first, second, comparator, {stopOnFirstFail, shouldCluster, clustersSize}, ({diffArea, diffClusters}) => {
const diffBounds = diffArea.area;
callback(null, {equal: result.isEmpty(), metaInfo, diffBounds});
callback(null, {equal: diffArea.isEmpty(), metaInfo, diffBounds, diffClusters});
});

@@ -195,8 +195,8 @@ });

getDiffPixelsCoords(first, second, comparator, opts, (result) => {
if (result.isEmpty()) {
getDiffPixelsCoords(first, second, comparator, opts, ({diffArea}) => {
if (diffArea.isEmpty()) {
return callback(null, null);
}
callback(null, result.area);
callback(null, diffArea.area);
});

@@ -203,0 +203,0 @@ });

@@ -6,3 +6,4 @@ 'use strict';

REQUIRED_IMAGE_FIELDS: ['source', 'boundingBox'],
REQUIRED_BOUNDING_BOX_FIELDS: ['left', 'top', 'right', 'bottom']
REQUIRED_BOUNDING_BOX_FIELDS: ['left', 'top', 'right', 'bottom'],
CLUSTERS_SIZE: 10
};
'use strict';
module.exports = class DiffArea {
static create() {
return new DiffArea();
}
constructor() {

@@ -19,4 +23,12 @@ this._diffArea = {left: Infinity, top: Infinity, right: -Infinity, bottom: -Infinity};

this._updated = true;
return this;
}
isPointInArea(x, y, radius) {
const {left, top, right, bottom} = this._diffArea;
return x >= (left - radius) && x <= (right + radius) && y >= (top - radius) && y <= (bottom + radius);
}
isEmpty() {

@@ -23,0 +35,0 @@ return !this._updated;

@@ -6,2 +6,3 @@ 'use strict';

const DiffArea = require('./diff-area');
const DiffClusters = require('./diff-clusters');
const validators = require('./validators');

@@ -40,2 +41,6 @@

const getDiffClusters = (diffClusters, diffArea, {shouldCluster}) => {
return shouldCluster ? diffClusters.clusters : [diffArea.area];
};
exports.getDiffPixelsCoords = (png1, png2, predicate, opts, callback) => {

@@ -53,2 +58,3 @@ if (!callback) {

const diffArea = new DiffArea();
const diffClusters = new DiffClusters(opts.clustersSize);

@@ -71,5 +77,8 @@ const processRow = (y) => {

diffArea.update(actX, actY);
if (opts.shouldCluster) {
diffClusters.update(actX, actY);
}
if (stopOnFirstFail) {
return callback(diffArea);
return callback({diffArea, diffClusters: getDiffClusters(diffClusters, diffArea, opts)});
}

@@ -84,3 +93,3 @@ }

} else {
callback(diffArea);
callback({diffArea, diffClusters: getDiffClusters(diffClusters, diffArea, opts)});
}

@@ -87,0 +96,0 @@ });

{
"name": "looks-same",
"version": "7.0.0",
"version": "7.1.0",
"description": "Pure node.js library for comparing PNG-images, taking into account human color perception.",

@@ -13,2 +13,3 @@ "main": "index.js",

"concat-stream": "^1.6.2",
"js-graph-algorithms": "1.0.18",
"lodash": "^4.17.3",

@@ -15,0 +16,0 @@ "parse-color": "^1.0.0",

@@ -91,7 +91,14 @@ # LooksSame

### Getting diff clusters
Looksame returns diff bounds divided into clusters. You can pass clusters size using `clustersSize` option.
```javascript
looksSame('image1.png', 'image2.png', {stopOnFirstFail: false}, function(error, {equal, diffBounds}) {
looksSame('image1.png', 'image2.png', {stopOnFirstFail: false}, function(error, {equal, diffBounds, diffClusters}) {
// {
// equal: false,
// diffBounds: {left: 10, top: 10, right: 20, bottom: 20}
// diffClusters: [
// {left: 10, top: 10, right: 14, bottom: 14},
// {left: 16, top: 16, right: 20, bottom: 20}
// ]
// }

@@ -98,0 +105,0 @@ });

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc