Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 17 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ It is a modification of [Resemble.js](https://github.com/Huddle/Resemble.js)

### Example

Retrieve basic analysis on image.
##### Retrieve basic analysis on image.

```javascript
var api = resemble(fileData).onComplete(function(data){
Expand All @@ -27,7 +27,7 @@ var api = resemble(fileData).onComplete(function(data){
});
```

Use resemble to compare two images.
##### Use resemble to compare two images.

```javascript
var diff = resemble(file).compareTo(file2).ignoreColors().onComplete(function(data){
Expand All @@ -43,15 +43,28 @@ var diff = resemble(file).compareTo(file2).ignoreColors().onComplete(function(da
});
```

You can also change the comparison method after the first analysis.
##### You can also change the comparison method after the first analysis.

```javascript
// diff.ignoreNothing();
// diff.ignoreColors();
diff.ignoreAntialiasing();
```

And change the output display style.
##### Specify matching Box for image comparsion

```javascript
diff.ignoreRectangles([[325,170,100,40], [10,10,200,200]]);
```
- Ignores matched rectangles
- <[Array<Array[x, y, width, height]>]>
```javascript
diff.includeRectangles([[325,170,100,40], [10,10,200,200]]);
```
- Compares only within given rectangles
- <[Array<Array[x, y, width, height]>]>

##### Change the output display style.

```javascript
resemble.outputSettings({
Expand Down
42 changes: 36 additions & 6 deletions resemble.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ var _this = {};
var ignoreAntialiasing = false;
var ignoreColors = false;
var ignoreRectangles = null;
var includeRectangles = null;

function triggerDataUpdate(){
var len = updateCallbackArray.length;
Expand Down Expand Up @@ -157,6 +158,13 @@ var _this = {};
}
}

function isWithinRectangle(x, y, rectangle) {
return (x >= rectangle[1]) &&
(x < rectangle[1] + rectangle[3]) &&
(y >= rectangle[0]) &&
(y < rectangle[0] + rectangle[2])
}

function isNumber(n) {
return !isNaN(parseFloat(n));
}
Expand Down Expand Up @@ -383,19 +391,35 @@ var _this = {};
for(rectagnlesIdx = 0; rectagnlesIdx < ignoreRectangles.length; rectagnlesIdx++) {
currentRectangle = ignoreRectangles[rectagnlesIdx];
//console.log(currentRectangle, verticalPos, horizontalPos);
if (
(verticalPos >= currentRectangle[1]) &&
(verticalPos < currentRectangle[1] + currentRectangle[3]) &&
(horizontalPos >= currentRectangle[0]) &&
(horizontalPos < currentRectangle[0] + currentRectangle[2])
) {
if (isWithinRectangle(verticalPos, horizontalPos, currentRectangle)) {
copyGrayScalePixel(targetPix, offset, pixel2);
//copyPixel(targetPix, offset, pixel1, pixel2);
return;
}
}
}

if (includeRectangles) {
var isWithinAnyRectangle = false;
for(rectagnlesIdx = 0; rectagnlesIdx < includeRectangles.length; rectagnlesIdx++) {
currentRectangle = includeRectangles[rectagnlesIdx];
if (isWithinRectangle(verticalPos, horizontalPos, currentRectangle)) {
isWithinAnyRectangle = true;
}
}
// Better solution but i'm not sure if you want to use reducers in your repo?
// var isWithinAnyRectangle = includeRectangles.reduce(function (acc, currentRectangle) {
// if(isWithinRectangle) {
// return true;
// }
// return acc;
// }, false);
if(!isWithinAnyRectangle) {
copyGrayScalePixel(targetPix, offset, pixel2);
return;
}
}

if (ignoreColors){

addBrightnessInfo(pixel1);
Expand Down Expand Up @@ -539,6 +563,12 @@ var _this = {};
ignoreRectangles: function(rectangles) {
ignoreRectangles = rectangles;
return self;
},
//array of rectangles, each rectangle is defined as (x, y, width. height)
//e.g. [[325, 170, 100, 40]]
includeRectangles: function(rectangles) {
includeRectangles = rectangles;
return self;
},
repaint: function(){
if(hasMethod) { param(); }
Expand Down