Warm tip: This article is reproduced from serverfault.com, please click

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

(node.js - How Can I Return Specified Image Size From Google Cloud Storage With Node API?)

发布于 2017-04-13 01:19:04

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

这是工作代码。我只需要返回较小的图像,例如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中执行此操作,因此我猜想可能有一种在node中执行此操作的方法吗?

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

Questioner
Luke Schlangen
Viewed
0
jonc.js 2017-04-13 20:12:46

本文应该助你一臂之力 “使用Google Cloud Platform上传,调整大小和提供图像” @Lipis https://medium.com/google-cloud/uploading-resizing-and-serving-images-with-google -云平台-ca9631a2c556