Passer au contenu principal
Menu
← BACK TO WORK

Serverless Image Process

Azure Functions

Traitement d'images automatique (resize/convert) via Azure Functions.

ClientProjet Lab
RoleDéveloppeur Cloud
Year2024
StackMicrosoft Azure, Python, Blob Storage, Functions
Serverless Image Process

THE CHALLENGE

Optimiser les coûts d'exécution et gérer efficacement les temps de cold start des fonctions.

__init__.py
1
import logging
2
import azure.functions as func
3
from PIL import Image
4
import io
5
 
6
def main(myblob: func.InputStream, outputblob: func.Out[bytes]):
7
    logging.info(f"Processing blob: {myblob.name}")
8
 
9
    # Load image
10
    img = Image.open(io.BytesIO(myblob.read()))
11
 
12
    # Resize to thumbnail
13
    img.thumbnail((300, 300))
14
 
15
    # Convert to bytes
16
    output = io.BytesIO()
17
    img.save(output, format='JPEG', quality=85)
18
 
19
    # Write to output blob
20
    outputblob.set(output.getvalue())
Detail View

Explore More

All Projects