我用过这个Background image thumbnail processing with Azure Functions and NodeJS创建缩略图的文章。图像创建成功。但是图像的大小已增加。这是怎么回事?它一定很小吧?我该如何解决这个奇怪的问题?
这是 Blob 存储上的原始图像
处理后(缩略图)
这是 Azure 函数( Node ):
var Jimp = require("jimp");
module.exports = (context, myBlob) => {
// Read image with Jimp
Jimp.read(myBlob).then((image) => {
// Manipulate image
image
.resize(200, Jimp.AUTO)
.greyscale()
.getBuffer(Jimp.MIME_JPEG, (error, stream) => {
// Check for errors
if (error) {
context.log(`There was an error processing the image.`);
context.done(error);
}
else {
context.log(`Successfully processed the image`);
// Bind the stream to the output binding to create a new blob
context.done(null, stream);
}
});
});
};
最佳答案
我已经找到了解决方案。
The default quality for JPEGs is 100. You should set this to something lower to gain compression:
您可以在这里阅读更多相关信息:Image is resized down and gets bigger file size
我必须设置.quality(50)
,如下所示。此问题仅与JPEG
有关。
var Jimp = require("jimp");
module.exports = (context, myBlob) => {
// Read image with Jimp
Jimp.read(myBlob).then((image) => {
// Manipulate image
image
.resize(200, Jimp.AUTO)
.greyscale()
.quality(50) // set the quality for JPEGs
.getBuffer(Jimp.MIME_JPEG, (error, stream) => {
// Check for errors
if (error) {
context.log(`There was an error processing the image.`);
context.done(error);
}
else {
context.log(`Successfully processed the image`);
// Bind the stream to the output binding to create a new blob
context.done(null, stream);
}
});
});
};
关于node.js - Azure Functions,缩略图尺寸大于原始图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41842633/