diff --git a/lib/convenience.js b/lib/convenience.js index 9f5c924..e2978af 100644 --- a/lib/convenience.js +++ b/lib/convenience.js @@ -8,4 +8,5 @@ module.exports = function (proto) { require("./convenience/morph")(proto); require("./convenience/sepia")(proto); require("./convenience/autoOrient")(proto); + require("./convenience/avatar")(proto); } diff --git a/lib/convenience/avatar.js b/lib/convenience/avatar.js new file mode 100644 index 0000000..5429cd6 --- /dev/null +++ b/lib/convenience/avatar.js @@ -0,0 +1,43 @@ +var fs = require("fs"); + +module.exports = function (proto) { + + proto.avatar = function avatar (name, callback) { + var self = this; + + self.size(function (err, size) { + if (err) { + return callback.apply(self, arguments); + } + + self.original = self.source; + self.source = ''; + + + self + .in("-size", size.width + "x" + size.height) + .in("xc:#ffffff00") + .drawCircle(size.width / 2, size.height / 2, size.width / 6, size.height / 6) + .write('mask.png', function(err) + { + if (err) { + return callback.apply(self, arguments); + } + + self + .subCommand("composite") + .in('-compose', 'In', self.original, 'mask.png') + .write(name, function(err) + { + fs.unlink("mask.png"); + if (err) { + return callback.apply(self, arguments); + } + callback.apply(self, arguments); + }); + }); + }); + + return self; + }; +}; diff --git a/test/avatar.js b/test/avatar.js new file mode 100644 index 0000000..dbd76c2 --- /dev/null +++ b/test/avatar.js @@ -0,0 +1,27 @@ + +var assert = require('assert') + +module.exports = function (gm, dir, finish, GM) { + + if (!GM.integration) + return finish(); + + gm + .avatar(__dirname + '/fixtures/avatar.png', function(err) + { + if(err) + { + finish(err); + } + else + { + gm.compare(__dirname + '/fixtures/avatar.png', __dirname + '/fixtures/avatar-compare.png', + function (err, isEqual) + { + if (err) return handle(err); + assert(isEqual); + finish(); + }) + } + }); +} diff --git a/test/fixtures/avatar-compare.png b/test/fixtures/avatar-compare.png new file mode 100644 index 0000000..6f06a3b Binary files /dev/null and b/test/fixtures/avatar-compare.png differ