Skip to content

Instantly share code, notes, and snippets.

@MichaelMarner
Last active Nov 3, 2017
Embed
What would you like to do?
Lambda image resize APIGateway
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