This example shows how to perform simple image manipulations with Pillow (PIL) behind a FastAPI endpoint on Wasmer Edge.
https://python-pillow-example.wasmer.app
main.py implements a /process route that accepts three query parameters: url, rotate, and crop.
- Download –
requests.get(url)fetches the remote image and loads it withImage.open(BytesIO(...)). - Transform – If
rotateis provided, the image rotates withexpand=True; ifcropis provided (left,top,right,bottom), the image is cropped accordingly. - Return – The image is saved to an in-memory buffer as PNG and returned as a streaming response.
Invalid crop strings or download failures are handled with descriptive HTTP errors.
python -m venv .venv
source .venv/bin/activate
pip install -r requirements.txt
uvicorn main:app --host 0.0.0.0 --port 8000 --reloadThen try:
curl "http://127.0.0.1:8000/process?url=https://picsum.photos/320&rotate=45&crop=0,0,200,200" \
--output rotated.png- Bundle
main.pyandrequirements.txtin your project. - Configure the start command to run Uvicorn:
uvicorn main:app --host 0.0.0.0 --port $PORT. - Deploy to Wasmer Edge and call
https://<your-subdomain>.wasmer.app/process?....