Azurefunction,缩略图图像大小比原始图像大

我已经使用这个背景图像缩略图处理与Azure函数和 NodeJS文章创build缩略图image.An图像创build成功,但图像的大小已经增加。怎么会发生? 它一定是非常小的没有? 我怎样才能解决这个奇怪的问题?

这是Blob存储上的原始图像

在这里输入图像说明

在这里输入图像说明

在这里输入图像说明

处理后(缩略图)

在这里输入图像说明

在这里输入图像说明

在这里输入图像说明

这是Azurefunction(节点):

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); } }); }); }; 

我find了一个解决scheme。

JPEG的默认质量是100.您应该将其设置为较低的值以获得压缩:

您可以在这里阅读更多信息: 图像被resize,并获得更大的文件大小

我必须设置如下所示的.quality(50) 。这个问题只与JPEGs

 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); } }); }); };