Created
September 26, 2016 14:49
-
-
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.
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
{ | |
"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 | |
} |
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
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