Skip to content

Commit

Permalink
added isnude method to simplify usage; changed test to reflect change
Browse files Browse the repository at this point in the history
  • Loading branch information
goddamnbugs committed May 7, 2011
1 parent e55163c commit 423e4ef
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 31 deletions.
30 changes: 30 additions & 0 deletions lib/node-nude.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,34 @@ nude.prototype.scan = function(callback){
myWorker.terminate();
}
};
nude.prototype.isnude = function(filename, callback) {
var Canvas = require('canvas')
, Image = Canvas.Image
, fs = require('fs');

var img = new Image;

img.onerror = function(err){
throw err;
};

var self = this;
img.onload = function(){
var width = img.width
, height = img.height
, canvas = new Canvas(width, height)
, ctx = canvas.getContext('2d');
console.log(img);
ctx.drawImage(img, 0, 0, width, height);
self.init(canvas);
self.load(img);
self.scan(function(result) {
callback(result);
});
};

//img.src = __dirname + '/images/3.jpg';
img.src = filename;

};
exports.nude = nude;
41 changes: 10 additions & 31 deletions tests/test.nude.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,34 +2,13 @@
* test.nude.js
*/

var Canvas = require('canvas')
, Image = Canvas.Image
, fs = require('fs')
, nude = new (require('../lib/node-nude')).nude();

var img = new Image
, start = new Date;

img.onerror = function(err){
throw err;
};

img.onload = function(){
var width = img.width
, height = img.height
, canvas = new Canvas(width, height)
, ctx = canvas.getContext('2d');
console.log(img);
ctx.drawImage(img, 0, 0, width, height);
nude.init(canvas);
nude.load(img);
nude.scan(function(result) {
if (result) {
console.log(img.src + " : Nude!!");
} else {
console.log(img.src + " : No nude!!");
}
});
};

img.src = __dirname + '/images/3.jpg';
var nude = new (require('../lib/node-nude')).nude();

var filename = __dirname + '/images/4.jpg';
nude.isnude(filename, function(result) {
if (result) {
console.log(filename + " : Nude!!");
} else {
console.log(filename + " : No nude!!");
}
});

0 comments on commit 423e4ef

Please sign in to comment.