Switch image resizing example from 'jimp' to 'sharp' because it's far faster

This commit is contained in:
SteveSandersonMS
2016-06-07 16:06:15 +01:00
parent 3e82d94f1c
commit 3440aa4344
3 changed files with 15 additions and 14 deletions

View File

@@ -1,15 +1,9 @@
var Jimp = require('jimp');
var sharp = require('sharp');
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') });
});
});
sharp(physicalPath)
.resize(maxWidth > 0 ? maxWidth : null, maxHeight > 0 ? maxHeight : null)
.toBuffer(function (err, buffer) {
cb(err, { base64: buffer && buffer.toString('base64') });
});
}