skins.js 832 B

1234567891011121314151617181920212223242526272829303132
  1. var lwip = require('lwip');
  2. var exp = {};
  3. // extracts the face from an image +buffer+
  4. // save it to a file called +outname+
  5. exp.extract_face = function(buffer, outname, callback) {
  6. lwip.open(buffer, "png", function(err, image) {
  7. if (err) throw err;
  8. image.batch()
  9. .crop(8, 8, 15, 15)
  10. .writeFile(outname, function(err) {
  11. if (err) throw err;
  12. callback();
  13. });
  14. });
  15. };
  16. // resizes the image file +inname+ to +size+ by +size+ pixels
  17. // +callback+ is a buffer of the resized image
  18. exp.resize_img = function(inname, size, callback) {
  19. lwip.open(inname, function(err, image) {
  20. if (err) throw err;
  21. image.batch()
  22. .resize(size, size, "nearest-neighbor") // nearest-neighbor doesn't blur
  23. .toBuffer('png', function(err, buffer) {
  24. callback(buffer);
  25. });
  26. });
  27. };
  28. module.exports = exp;