Skip to content

Instantly share code, notes, and snippets.

@tomconte
Created September 26, 2016 14:49
Show Gist options
  • Save tomconte/8a4eb26d21f89881d9008f589e3b2754 to your computer and use it in GitHub Desktop.
Save tomconte/8a4eb26d21f89881d9008f589e3b2754 to your computer and use it in GitHub Desktop.
Node.JS Azure Function to resize images, using the pure JavaScript Jimp library. A Blob Trigger is used to detect incoming files, and a Blob Output binding is used to write the scaled image.
{
"bindings": [
{
"name": "inputBlob",
"type": "blobTrigger",
"dataType": "binary",
"direction": "in",
"path": "images-in/{name}",
"connection": "function821251a1b074_STORAGE"
},
{
"type": "blob",
"name": "outputBlob",
"path": "images-out/{name}",
"connection": "function821251a1b074_STORAGE",
"direction": "out"
}
],
"disabled": false
}
var Jimp = require("jimp");
module.exports = function(context, inputBlob) {
Jimp.read(inputBlob, function(err, image) {
image.scale(0.5);
image.getBuffer(Jimp.AUTO, function(error, imageData) {
context.log('Node.JS blob trigger function resized ' + context.bindingData.name + ' to ' + image.bitmap.width + 'x' + image.bitmap.height);
context.bindings.outputBlob = imageData;
context.done();
});
});
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment