in processing-pipelines/image-v2/watermarker/csharp/Function.cs [51:88]
public async Task HandleAsync(HttpContext context)
{
_logger.LogInformation("Function received request");
try
{
var (bucket, file, labels) = await _requestReader.ReadCloudStorageAndLabelsData(context);
using (var inputStream = new MemoryStream())
{
var client = await StorageClient.CreateAsync();
await client.DownloadObjectAsync(bucket, file, inputStream);
_logger.LogInformation($"Downloaded '{file}' from bucket '{bucket}'");
using (var outputStream = new MemoryStream())
{
inputStream.Position = 0; // Reset to read
using (var image = Image.Load(inputStream))
{
using (var imageProcessed = image.Clone(ctx => ApplyScalingWaterMarkSimple(ctx, _font, labels, Color.DeepSkyBlue, 5)))
{
_logger.LogInformation($"Added watermark to image '{file}'");
imageProcessed.SaveAsJpeg(outputStream);
}
}
var outputObjectName = $"{Path.GetFileNameWithoutExtension(file)}-watermark.jpeg";
await client.UploadObjectAsync(_outputBucket, outputObjectName, "image/jpeg", outputStream);
_logger.LogInformation($"Uploaded '{outputObjectName}' to bucket '{_outputBucket}'");
}
}
}
catch (Exception e)
{
_logger.LogError($"Error processing: " + e.Message);
throw e;
}
}