Last active
November 3, 2017 02:08
-
-
Save MichaelMarner/56d7ab8212bbf8ac20f09c4c9679aa6b to your computer and use it in GitHub Desktop.
Lambda image resize APIGateway
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
import { APIGatewayEvent, Context, Callback } from 'aws-lambda'; | |
import * as Jimp from 'jimp'; | |
export async function resize( | |
event: APIGatewayEvent, | |
context: Context, | |
callback: Callback | |
) { | |
const image = await Jimp.read(event.queryStringParameters.src); | |
await image.cover(Number(event.queryStringParameters.w), Number(event.queryStringParameters.h)); | |
image.getBuffer(Jimp.MIME_JPEG, (err, buffer: Buffer) => { | |
callback(null, { | |
statusCode: 200, | |
headers: { 'Content-Type': 'image/jpeg' }, | |
body: buffer.toString('base64') | |
}); | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment