sharp
sharp copied to clipboard
Composite Function in Google Cloud Service
Hi, I'm trying to perform a composite operation on an image that I am sending through a stream in GCS. I've already done some prior research on this, I'm aware that the composite function doesn't support streams as an input via issue #2200.
I'm considering, as a solution, converting my file input to a raw image buffer that can be read by the composite function before then turning it into a read stream that I can then send through the render output, performing any extra image transformations that I'd like to then. Any ideas on how I would go about doing that?
// Transformer sets the file attributes based on prior queries
const transformer = sharp()
.resize(resize)
.modulate({
brightness: brightnessVal
})
.toFormat(ext);
// Loads the pictures from bucket
const gcs = new Storage();
let fileOne = gcs.bucket('bucketName').file(imageOneParameters.fileName);
let fileTwo = gcs.bucket('bucketName').file(imageTwoParameters.fileName);
//v DO THE COMPOSITE HERE? v
// fileOne + fileTwo = compositeFile ???
// Create a stream
let stream = compositeFile.createReadStream()
stream.on('error', function(err) {
console.error(err);
res.sendStatus(err.code).end(err);
});
// Add headers
res.setHeader("content-type", "image/"+ext);
res.setHeader("cache-control", "public, max-age=31536000, immutable");
// Render
stream.pipe(transformer).pipe(res);
});