-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathFunction1.cs
More file actions
53 lines (44 loc) · 2.12 KB
/
Function1.cs
File metadata and controls
53 lines (44 loc) · 2.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
using System.IO;
using System.Threading.Tasks;
using Microsoft.Azure.WebJobs;
using Microsoft.Azure.WebJobs.Host;
using Microsoft.Extensions.Logging;
using Microsoft.WindowsAzure.Storage;
using Microsoft.WindowsAzure.Storage.Blob;
using SixLabors.ImageSharp;
using SixLabors.ImageSharp.PixelFormats;
using SixLabors.ImageSharp.Processing;
namespace ImageProcessor
{
public static class Function1
{
static string storageAccountConnectionString = System.Environment.GetEnvironmentVariable("AzureWebJobsStorage");
static string thumbContainerName = System.Environment.GetEnvironmentVariable("myContainerName");
[FunctionName("Function1")]
public static async Task Run([BlobTrigger("rawimages/{name}", Connection = "")]Stream inputBlob, string name, ILogger log)
{
log.LogInformation($"C# Blob trigger function Processed blob\n Name:{name} \n Size: {inputBlob.Length} Bytes");
// Get the blobname from the event's JObject. updated PR
string blobName = name;
// done
// Retrieve storage account from connection string.
CloudStorageAccount storageAccount = CloudStorageAccount.Parse(storageAccountConnectionString);
// Create the blob client.
CloudBlobClient blobClient = storageAccount.CreateCloudBlobClient();
// Retrieve reference to a previously created container.
CloudBlobContainer container = blobClient.GetContainerReference(thumbContainerName);
await container.CreateIfNotExistsAsync();
// Create reference to a blob named "blobName".
CloudBlockBlob blockBlob = container.GetBlockBlobReference(blobName);
var format = Image.DetectFormat(inputBlob);
using (Image<Rgba32> img = Image.Load(inputBlob))
{
img.Mutate(ctx => ctx.Resize(150, 150));
using (var stream = await blockBlob.OpenWriteAsync())
{
img.Save(stream, format);
}
}
}
}
}