In this article,
I am going to show,
-
what is Azure Function?
-
How we can create an Azure Function from Azure Portal?
-
How we can trigger our Azure Function?
I am going to
explain all above through an example. I have created a Storage Account with two
container
- source
- destination
What I am going to create in this article:
Azure
Portal – Function App – BlobTriggerFunction. I will upload an Image to source Container and will process on it
and after resizing it, I will save this pic to destination Container.
Open Azure
Portal: https://portal.azure.com
Login with
you subscription.
Below is my
Azure Storage Account:

Image 1.
Now add a new
Azure Function:

Image 2.
Function App
has been created. Now add + to add new function.

Image 3.
Make sure Run time version is ~1 of newly created function App.

Image 4.
Now add a
trigger for this function. So here, I am going to use Blob Trigger.

Image 5.
Here we are
going to upload Images in source container and will process on it and will save
resized image in destination container.

Image 6.
Below is
default code.

Image 7.
Now add a project.json
file

Image 8.
Add below
code in your project.json file. Save it. It will install NuGet packages. See
log.
{
"frameworks":{
"net46":{
"dependencies":{
"ImageResizer":"4.0.5"
}
}
}
}

Image 9.
Now click on
Integrate on Left side.

Image 10.
Set output.

Image 11.
Open run.csx
file and add below code:
#r "System.Drawing"
using ImageResizer;
using System.Drawing;
using System.Drawing.Imaging;
public static void Run(Stream inImage, string name, string extension, Stream
outImage, TraceWriter log)
{
log.Info($"C# Blob trigger
function Processed blob\n Name:{name} \n Size: {inImage.Length} Bytes");
var settings= new
ImageResizer.ResizeSettings
{
MaxWidth=250,
Format="jpg",
Quality=50
};
ImageResizer.ImageBuilder.Current.Build(inImage,outImage,settings);
}

Image 12.
Now upload an
image in source container from Azure portal or Storage Explorer:

Image 13.
Image
uploaded in source Container:

Image 14.
Blob will
trigger and will save Image in destination Container after resizing it:

Image 15.
Check your
Image J

Image 16.