Last active
November 17, 2021 03:29
-
-
Save tkhoa2711/8fbbaf6c4e8a54bcdd96f8db8d27a4d1 to your computer and use it in GitHub Desktop.
polaroid
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const response = event.Records[0].cf.response; | |
// ... | |
Sharp(imageBuffer, { | |
sequentialRead: true, | |
limitInputPixels: 2684026890, // raise default limit to 10x | |
}) | |
.resize({ | |
width: width, | |
withoutEnlargement: true, | |
}) | |
.toFormat("jpeg", { | |
mozjpeg: true, | |
progressive: true, | |
}) | |
.toBuffer() | |
.then((processedBuffer) => { | |
response.status = 200; | |
response.body = processedBuffer.toString("base64"); | |
response.bodyEncoding = "base64"; | |
response.headers["content-type"] = [ | |
{ key: "Content-Type", value: "image/jpeg" }, | |
]; | |
response.headers["cache-control"] = [ | |
{ key: "Cache-Control", value: "max-age=31536000" }, // 1 year | |
]; | |
callback(null, response); | |
}) | |
.catch((err) => { | |
console.error("Exception while reading source image", err); | |
callback(null, response); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment