Add image resizing example. Currently used base64 encoded data transfer and the 'jimp' module, neither of which are fast. Will replace these shortly.

This commit is contained in:
SteveSandersonMS
2016-06-07 15:55:06 +01:00
parent 8dbd143857
commit 3e82d94f1c
7 changed files with 110 additions and 1 deletions

View File

@@ -0,0 +1,15 @@
var Jimp = require('jimp');
module.exports = function(cb, physicalPath, mimeType, maxWidth, maxHeight) {
Jimp.read(physicalPath, function (err, loadedImage) {
if (err) {
cb(err);
}
loadedImage
.contain(maxWidth > 0 ? maxWidth : Jimp.AUTO, maxHeight > 0 ? maxHeight : Jimp.AUTO)
.getBuffer(mimeType, function(err, buffer) {
cb(err, { base64: buffer && buffer.toString('base64') });
});
});
}