node.js - Azure Functions,缩略图尺寸大于原始图像

标签 node.js image azure thumbnails azure-functions

我用过这个Background image thumbnail processing with Azure Functions and NodeJS创建缩略图的文章。图像创建成功。但是图像的大小已增加。这是怎么回事?它一定很小吧?我该如何解决这个奇怪的问题?

这是 Blob 存储上的原始图像

enter image description here

enter image description here

enter image description here

处理后(缩略图)

enter image description here

enter image description here

enter image description here

这是 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/

相关文章:

c# - 无法加载文件或程序集 Microsoft.Owin 3.0.0 到 3.0.1

node.js - Mongoose - 如何将模式中间件接入 'init' 事件?

node.js - 将整个用户放入 session 中与仅将 Node/express 的用户 ID 放入 session 中是否安全?

javascript - 使用 BookshelfJS/KnexJS 的 NodeJS 脚本中的基本表关联

node.js - RabbitMQ 与 nodejs

image - Github 页面 jekyll 图像未加载

html - 在不保持纵横比的情况下拉伸(stretch) svg 背景

css - 如何在保持矩形背景颜色的同时将 ImagePattern 添加到矩形

c# - 如何使用 API Graph 从 Azure Function 在 SharePoint Online 中正确进行身份验证?

azure - 尝试将用户分配给应用程序时出错