Azure Functions,缩略图图像大小大于原始图像

Azure Functions , Thumbnail image size is larger than original image

我已经使用这篇 Background image thumbnail processing with Azure Functions and NodeJS 文章创建了缩略图 image.An 图片已创建 successfully.But 图片大小已确定 increased.How 会发生这种情况吗?它一定很小,不是吗?我该如何解决这个奇怪的问题?

这是 Blob 存储上的原始图像

处理后(缩略图)

这是 Azure 函数(节点):

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) below.This 问题仅在于 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);

                }

            });

    });

};

我遇到了同样的问题,我使用了 sharp,它对我有用。如果您需要更多帮助,请告诉我,我会分享我完整的功能代码。

 const sharp = require('sharp');
 const thumbnailWidth = 250
 module.exports = async (context, myBlob) => {
    
      let thumbBuffer
      const image = await sharp(myBlob)
      image.resize({ width: thumbnailWidth })
      return thumbBuffer = await image.toBuffer()
 }