mirror of
https://github.com/aspnet/JavaScriptServices.git
synced 2025-12-22 17:47:53 +00:00
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:
15
samples/misc/NodeServicesExamples/Node/resizeImage.js
Normal file
15
samples/misc/NodeServicesExamples/Node/resizeImage.js
Normal 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') });
|
||||
});
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user