in Application/StepFunctions/thumbnail/Function.cs [37:73]
public async Task<ThumbnailInfo> FunctionHandler(Input input, ILambdaContext context)
{
var logger = new ImageRecognitionLogger(input, context);
var size = input.ExtractedMetadata.Dimensions;
var scalingFactor = Math.Min(
MAX_WIDTH / size.Width,
MAX_HEIGHT / size.Height
);
var width = Convert.ToInt32(scalingFactor * size.Width);
var height = Convert.ToInt32(scalingFactor * size.Height);
var image = await GenerateThumbnail(input.Bucket, input.SourceKey, width, height);
var destinationKey = input.SourceKey.Replace("uploads", "resized");
using (var stream = new MemoryStream())
{
await image.thumbnailImage.SaveAsync(stream, image.format);
stream.Position = 0;
context.Logger.LogLine($"Saving thumbnail to {destinationKey} with size {stream.Length}");
await S3Client.PutObjectAsync(new PutObjectRequest
{
BucketName = input.Bucket,
Key = destinationKey,
InputStream = stream
});
await logger.WriteMessageAsync(new MessageEvent {Message = "Photo thumbnail created"},
ImageRecognitionLogger.Target.All);
return new ThumbnailInfo(width, height, destinationKey, input.Bucket);
}
}