使用Nodejs中的Graphicsmagick调整图像大小会生成emty文件

时间:2021-08-17 23:10:09

I'm trying to resize an existing image and then upload it to Azure storage, but no success yet ...

我正在尝试调整现有映像的大小,然后将其上传到Azure存储,但还没有成功......

gm("https://sinkroon.blob.core.windows.net/sinkroonboilerplate/dakterras1.jpg")
.resize(50, 50)
.stream(function (err, stdout, stderr) {
    var writeStream = blobSvc.createWriteStreamToBlockBlob(
    containerName,
    'test.jpg',
    { contentType: 'image/jpg' },
    function (error, result, response) {
         if (error) {
             console.error(error);
         } else {
         }
    });
    stdout.pipe(writeStream);
});

This generates an empty image : https://sinkroon.blob.core.windows.net/sinkroonboilerplate/test.jpg

这会生成一个空图像:https://sinkroon.blob.core.windows.net/sinkroonboilerplate/test.jpg

Can't figure out what I'm doing wrong ... Anyone ?

无法弄清楚我做错了什么......有人吗?

1 个解决方案

#1


2  

For this case i use this:

对于这种情况,我使用这个:

var request = require('request');
var lwip    = require('lwip');
request({url: url, encoding:null}, function (err, response, imageBuffer) {
    var imageFormat = response.headers["content-type"].match(/(png|jpg|jpeg)/)[0];  
        lwip.open( imageBuffer, imageFormat, function(err, image){
            if (err || !image) throw err;
            image.resize(196, 196, function(err, image){
                if (err || !image) throw err;
                image.toBuffer(imageFormat, function(err, buffer){
                     //here you buffer you can save image in file with FS
                });
            });
        });
    }
});

#1


2  

For this case i use this:

对于这种情况,我使用这个:

var request = require('request');
var lwip    = require('lwip');
request({url: url, encoding:null}, function (err, response, imageBuffer) {
    var imageFormat = response.headers["content-type"].match(/(png|jpg|jpeg)/)[0];  
        lwip.open( imageBuffer, imageFormat, function(err, image){
            if (err || !image) throw err;
            image.resize(196, 196, function(err, image){
                if (err || !image) throw err;
                image.toBuffer(imageFormat, function(err, buffer){
                     //here you buffer you can save image in file with FS
                });
            });
        });
    }
});