Skip to content
This repository has been archived by the owner on Oct 14, 2023. It is now read-only.

Latest commit

 

History

History

blob-trigger-watermark-blob-out-binding

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 
 
 

blob-trigger-watermark-blob-out-binding (Python)

Sample Description Trigger In Bindings Out Bindings
blob-trigger-watermark-blob-out-binding Azure Function Python Sample that watermarks an image. This function triggers on an input blob (image) and adds a watermark by calling into the Pillow library. The resulting composite image is then written back to blob storage using a blob output binding. Blob Storage Blob Storage Blob Storage

Sample output

Configurations

As specified in functions.json, you need Azure Storage account for triggering functions, input & output binding.

{
  "scriptFile": "__init__.py",
  "bindings": [
    {
      "name": "blobin",
      "type": "blobTrigger",
      "direction": "in",
      "path": "input/{blobname}.{blobextension}",
      "connection": "MyStorageConnectionString"
    },
    {
      "name": "blobout",
      "type": "blob",
      "direction": "out",
      "path": "output/{blobname}_watermarked.jpg",
      "connection": "MyStorageConnectionString"
    }
  ]
}

Create Azure Storage Account

Create an Azure Storage Account

RESOURCE_GROUP="rg-testfunctions"
REGION="japaneast"
STORAGE_ACCOUNT="teststore"
az storage account create --name $STORAGE_ACCOUNT \
    --location $REGION \
    --resource-group $RESOURCE_GROUP \
    --sku Standard_LRS

Create Blob Storage Containers

Create 2 blob containers in the storage you've created: input and output

# Get Storage Key
ACCESS_KEY=$(az storage account keys list --account-name $STORAGE_ACCOUNT --resource-group $RESOURCE_GROUP --output tsv |head -1 | awk '{print $3}')

az storage container create  \
    --name "input" \
    --account-name $STORAGE_ACCOUNT \
    --account-key $ACCESS_KEY

az storage container create  \
    --name "output" \
    --account-name $STORAGE_ACCOUNT \
    --account-key $ACCESS_KEY

How to develop and publish the functions

Local development

func host start

Try it out

Upload an image to input blob container under the storage account to try it out. The final watermarked composite should surface in the output container. When developing locally it should also render it on screen if you have imagemagick or xv installed (works on Mac, Linux, WSL with Xming X server, unsure what happens on native Windows).

Publish the function to the cloud

Publish the function to the cloud

FUNCTION_APP_NAME="MyFunctionApp"
func azure functionapp publish $FUNCTION_APP_NAME --build-native-deps --no-bundler

Add Functions App Settings

FUNCTION_STORAGE_CONNECTION="*************"
az webapp config appsettings set \
  -n $FUNCTION_APP_NAME \
  -g $RESOURCE_GROUP \
  --settings \
    MyStorageConnectionString=$FUNCTION_STORAGE_CONNECTION