forked from peter-mouland/node-resemble-v2
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d248e81
commit c55eb10
Showing
5 changed files
with
119 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
[*] | ||
end_of_line = lf | ||
insert_final_newline = true | ||
indent_style = space | ||
trim_trailing_whitespace = true | ||
|
||
[*.js] | ||
indent_size = 2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
.DS_Store | ||
.idea | ||
node_modules | ||
*.log |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,34 @@ | ||
# node-resemble-v2 | ||
node-resemble-v2 | ||
============= | ||
|
||
A new Node port of [Resemble.js v2](https://github.com/Huddle/Resemble.js). | ||
|
||
##Installation | ||
|
||
```bash | ||
$ npm i node-resemble-v2 | ||
``` | ||
|
||
##Prerequisites | ||
|
||
[Cairo](http://cairographics.org/) is required for [node-canvas](https://github.com/Automattic/node-canvas), installation instructions can be found node-canvas [Wiki](https://github.com/Automattic/node-canvas/wiki/_pages). | ||
|
||
##Example | ||
|
||
```js | ||
var fs = require('fs'); | ||
|
||
var resemble = require('node-resemble-v2'); | ||
|
||
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); | ||
}); | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
const canvas = require('canvas'); | ||
const imageType = require('image-type'); | ||
|
||
function overrideWindow() { | ||
const doc = {}; | ||
doc.createElement = function createElement(tag) { | ||
return (tag !== 'canvas') | ||
? false | ||
: new canvas(); | ||
}; | ||
return { | ||
document: doc | ||
}; | ||
} | ||
|
||
function overrideFileReader() { | ||
const FileReader = function FileReader() { }; | ||
FileReader.prototype.readAsDataURL = function readAsDataURL(buffer) { | ||
this.onload({ | ||
target: { | ||
result: "data:image/" + imageType(buffer) + ";base64," + buffer.toString('base64') + "" | ||
} | ||
}); | ||
}; | ||
return FileReader; | ||
} | ||
|
||
function overrideImage() { | ||
const Image = canvas.Image; | ||
Image.prototype.setAttribute = function setAttribute() { }; | ||
return Image; | ||
} | ||
|
||
module.exports = function exports() { | ||
if (typeof window === 'undefined') { | ||
global.window = overrideWindow(); | ||
} | ||
if (typeof FileReader === 'undefined') { | ||
global.FileReader = overrideFileReader(); | ||
} | ||
if (typeof Image === 'undefined') { | ||
global.Image = overrideImage(); | ||
} | ||
const resemblejs = require('resemblejs'); // eslint-disable-line global-require | ||
return resemblejs.apply(this, arguments); // eslint-disable-line prefer-rest-params | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
{ | ||
"name": "node-resemble-v2", | ||
"version": "1.0.0", | ||
"description": "Node API for ResembleJS (v2)", | ||
"main": "index.js", | ||
"scripts": { | ||
"test": "echo \"Error: no test specified\" && exit 1" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "git+ssh://[email protected]/peter-mouland/node-resemble-v2.git" | ||
}, | ||
"keywords": [ | ||
"resemblejs" | ||
], | ||
"author": "Peter Mouland", | ||
"license": "ISC", | ||
"bugs": { | ||
"url": "https://github.com/peter-mouland/node-resemble-v2/issues" | ||
}, | ||
"homepage": "https://github.com/peter-mouland/node-resemble-v2#readme", | ||
"dependencies": { | ||
"canvas": "^1.6.2", | ||
"image-type": "^2.1.0", | ||
"resemblejs": "^2.2.2" | ||
} | ||
} |