问题
I'm using cloud storage and it is working well, I just don't want to return the full-size image every time. I'm wondering if there is a way to specify a width to resize an image to when I request it?
Here is the WORKING code. I just need to return smaller images, say, 300px wide (maintaining original aspect ratio). This number could change or fluctuate, so I don't want to save a ton of different versions at different sizes unless I absolutely have to.
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();
});
I've found this site explaining how to do this in PHP, so I'm guessing there is probably a way to do this in node?
https://cloud.google.com/appengine/docs/standard/php/googlestorage/images
回答1:
This article should get you off on the right foot: “Uploading, Resizing and Serving images with Google Cloud Platform” @Lipis https://medium.com/google-cloud/uploading-resizing-and-serving-images-with-google-cloud-platform-ca9631a2c556
来源:https://stackoverflow.com/questions/43382043/how-can-i-return-specified-image-size-from-google-cloud-storage-with-node-api