Skip to content

Commit

Permalink
init
Browse files Browse the repository at this point in the history
  • Loading branch information
ddo committed Jul 2, 2014
1 parent a1254d4 commit 5dc8180
Show file tree
Hide file tree
Showing 5 changed files with 111 additions and 1 deletion.
34 changes: 33 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,36 @@
node-resemble
=============

Image analysis and comparison with HTML5
Node port of [Resemble.js](https://github.com/Huddle/Resemble.js).

##Installation

```bash
$ npm i node-resemble
```

##Note

[node-canvas](https://github.com/Automattic/node-canvas) is a [Cairo](http://cairographics.org/) backed Canvas implementation for NodeJS.

Unless previously installed you'll need Cairo. For system-specific installation view the node-canvas [Wiki](https://github.com/Automattic/node-canvas/wiki/_pages).

##Example

```js
var fs = require('fs');

var resemble = require('node-resemble');

var github_img1 = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAMAAAAoLQ9TAAAABGdBTUEAALGPC/xhBQAAAJlQTFRFJiYmJiYmJSUlJiYmKysrJiYmJSUlJiYmJSUlJCQkJiYmJycnJiYmJiYmJSUlJiYmJSUlJiYmJSUlJCQkJycnJCQkJycnJiYmJSUlJiYmJiYmJycnJiYmJiYmJSUlJycnJycnJCQkJSUlJiYmJiYmJycnJiYmJycnJiYmJSUlJiYmJiYmJycnJiYmEhISISEhJycnAAAAJiYmQmWwmAAAADJ0Uk5T9JNotgyiTK2KR0P7Zij+PYni/StBMdmBpKnq5tbw1VXsKu9RUM3O7cl8V5ql3w42+gB0ejcrAAAApElEQVQY012PRRIEMQwDs8zMOAzhyP9/3CYDl9XJ7irZEoOXldo5LW2YGWAUlVwIXpIyAZi6ytAor2rjgao2pgXjpFJglvLLdrbez4eT1TIny2QJS50WKCXTHLceDMA1cwLXHsQQjrkIhx4wRC5YRj2og0UW2Ll2P05RSP82g72/iJ6PMzL/FipOgIJIA6cQzEdPBT7eAZE20UO5b7jy7sr91f8BZR4qkBlEJUYAAAAASUVORK5CYII=';

var github_img2 = fs.readFileSync('./example.png');

resemble(github_img1).onComplete(function(data){
console.log(data);
});

resemble(github_img1).compareTo(github_img2).onComplete(function(data){
console.log(data);
});
```
15 changes: 15 additions & 0 deletions example.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
var fs = require('fs');

var resemble = require('./');

var github_img1 = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAMAAAAoLQ9TAAAABGdBTUEAALGPC/xhBQAAAJlQTFRFJiYmJiYmJSUlJiYmKysrJiYmJSUlJiYmJSUlJCQkJiYmJycnJiYmJiYmJSUlJiYmJSUlJiYmJSUlJCQkJycnJCQkJycnJiYmJSUlJiYmJiYmJycnJiYmJiYmJSUlJycnJycnJCQkJSUlJiYmJiYmJycnJiYmJycnJiYmJSUlJiYmJiYmJycnJiYmEhISISEhJycnAAAAJiYmQmWwmAAAADJ0Uk5T9JNotgyiTK2KR0P7Zij+PYni/StBMdmBpKnq5tbw1VXsKu9RUM3O7cl8V5ql3w42+gB0ejcrAAAApElEQVQY012PRRIEMQwDs8zMOAzhyP9/3CYDl9XJ7irZEoOXldo5LW2YGWAUlVwIXpIyAZi6ytAor2rjgao2pgXjpFJglvLLdrbez4eT1TIny2QJS50WKCXTHLceDMA1cwLXHsQQjrkIhx4wRC5YRj2og0UW2Ll2P05RSP82g72/iJ6PMzL/FipOgIJIA6cQzEdPBT7eAZE20UO5b7jy7sr91f8BZR4qkBlEJUYAAAAASUVORK5CYII=';

var github_img2 = fs.readFileSync('./example.png');

resemble(github_img1).onComplete(function(data){
console.log(data);
});

resemble(github_img1).compareTo(github_img2).onComplete(function(data){
console.log(data);
});
Binary file added example.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
34 changes: 34 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
var fs = require('fs');

var resemblejs = require('resemblejs');
var canvas = require('canvas');
var imageType = require('image-type');

module.exports = function() {
//override FileReader
this.FileReader = function(){};
this.FileReader.prototype.readAsDataURL = function(buffer) {
this.onload({
target: {
result: 'data:image/' + imageType(buffer) + ';base64,' + buffer.toString('base64')
}
});
};

//override Image
this.Image = canvas.Image;
this.Image.prototype.setAttribute = function() {};

//override document.createElement('canvas')
this.document = {
createElement: function(tag) {
if(tag !== 'canvas') {
return false;
}

return new canvas;
}
};

return resemblejs.resemble.apply(this, arguments);
};
29 changes: 29 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{
"name": "node-resemble",
"version": "1.1.1",
"description": "Image analysis and comparison with HTML5",
"main": "index.js",
"keywords": [
"comparison",
"visual",
"image",
"diff",
"compare",
"html5"
],
"repository": {
"type": "git",
"url": "https://[email protected]/ddo/node-resemble.git"
},
"author": "ddo <[email protected]> (http://ddo.me/)",
"license": "MIT",
"bugs": {
"url": "https://github.com/ddo/node-resemble/issues"
},
"homepage": "https://github.com/ddo/node-resemble",
"dependencies": {
"canvas": "^1.1.5",
"image-type": "^0.1.4",
"resemblejs": "^1.1.1"
}
}

0 comments on commit 5dc8180

Please sign in to comment.