如何使用Node API从Google Cloud Storage返回指定的图像大小?

我正在使用云存储,并且运行良好,我只是不想每次都返回完整大小的图像。 我想知道是否有一种方法来指定一个宽度来调整图像的大小,当我请求它?

这是工作代码。 我只需要返回较小的图像,比如300px宽(保持原始高宽比)。 这个数字可能会改变或波动,所以我不想保存大量不同的版本,除非我绝对必须。

var fileName = "Image.png"; var stream = bucket.file(fileName).createReadStream(); res.writeHead(200, { 'Content-Type': imageInfo.mime_type }); stream.on('data', function (data) { res.write(data); }); stream.on('error', function (err) { console.log('error reading stream', err); }); stream.on('end', function () { res.end(); }); 

我发现这个网站解释了如何在PHP中做到这一点,所以我猜可能有一种方法在节点中做到这一点?

https://cloud.google.com/appengine/docs/standard/php/googlestorage/images

这篇文章可以帮助您摆脱困境: “使用Google云端平台上传,resize和提供图片服务”@Lipis https://medium.com/google-cloud/uploading-resizing-and-serving-images-with-google -cloud平台,ca9631a2c556