Skip to content

zenigmadev/resizer-functionapp-poc

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Azure Image Resizer Function

Build Status Tests .NET License

A production-ready Azure Function application that dynamically resizes images stored in Azure Blob Storage via HTTP GET requests, supporting all popular image formats.

🎯 Features

Supported Image Formats

  • JPEG/JPG - With full quality control
  • PNG - Transparency preserved
  • GIF - Animated GIF support
  • BMP - Bitmap format
  • WebP - Modern web format

Capabilities

  • ✅ HTTP GET triggered
  • ✅ Dynamic resizing (width, height)
  • ✅ Automatic aspect ratio preservation
  • ✅ Quality control (1-100)
  • ✅ Format conversion (e.g., PNG → WebP)
  • ✅ Multiple resize modes (max, crop, pad, stretch)
  • ✅ CDN/Front Door cache support
  • ✅ Logic App integration
  • ✅ Application Insights monitoring
  • ✅ Comprehensive error handling and logging
  • ✅ Unit test coverage

📁 Project Structure

resizer-logicapp-poc/
├── src/                        # Main application code
│   ├── ImageResizer.cs         # Image resize logic
│   ├── Program.cs              # Function host configuration
│   ├── host.json               # Function host settings
│   ├── local.settings.json     # Local development settings
│   └── logic-app-workflow.json # Logic App integration
├── tests/                      # Test project
│   ├── ImageResizerTests.cs    # Unit tests
│   └── *.csproj                # Test project file
├── docs/                       # Documentation
│   └── DEPLOYMENT.md           # Deployment guide
├── .gitignore                  # Git ignore rules
└── README.md                   # This file

🚀 Quick Start

Prerequisites

Local Development

  1. Clone the repository:
git clone https://github.com/zenigmadev/resizer-logicapp-poc.git
cd resizer-logicapp-poc
  1. Configure local.settings.json:
{
  "IsEncrypted": false,
  "Values": {
    "AzureWebJobsStorage": "UseDevelopmentStorage=true",
    "FUNCTIONS_WORKER_RUNTIME": "dotnet-isolated",
    "StorageConnectionString": "YOUR_STORAGE_CONNECTION_STRING",
    "StorageContainerName": "images",
    "APPLICATIONINSIGHTS_CONNECTION_STRING": "YOUR_APP_INSIGHTS_CONNECTION_STRING"
  }
}
  1. Build the project:
cd src
dotnet build
  1. Run tests:
cd ../tests
dotnet test
  1. Start the function:
cd ../src
func start

📖 Usage

Basic URL Structure

https://<function-app-name>.azurewebsites.net/api/<image-path>?<parameters>

Query String Parameters

Parameter Alias Description Example
w width Width in pixels w=800
h height Height in pixels h=600
q quality Quality (1-100, default: 85) q=90
format output Output format (jpeg, png, webp, gif, bmp) format=webp
mode - Resize mode (max, crop, pad, stretch) mode=crop

Resize Modes

  • max (default): Fits within specified dimensions while preserving aspect ratio
  • crop: Crops to exact dimensions
  • pad: Fits within dimensions and pads empty space
  • stretch: Stretches to exact dimensions

Usage Examples

1. Resize to 800px width (aspect ratio preserved)

https://myapp.azurewebsites.net/api/photos/landscape.jpg?w=800

2. Resize to 600px height

https://myapp.azurewebsites.net/api/photos/portrait.png?h=600

3. Resize to exact 400x300 dimensions

https://myapp.azurewebsites.net/api/photos/product.jpg?w=400&h=300

4. Convert PNG to WebP and resize

https://myapp.azurewebsites.net/api/photos/logo.png?w=200&format=webp

5. High quality JPEG (quality 95)

https://myapp.azurewebsites.net/api/photos/hero.jpg?w=1920&q=95

6. Create square thumbnail (crop mode)

https://myapp.azurewebsites.net/api/photos/profile.jpg?w=150&h=150&mode=crop

7. Image in subfolder

https://myapp.azurewebsites.net/api/products/category1/item-photo.jpg?w=500

🔧 Deployment

Deploy with Azure CLI

# Create Function App
az functionapp create \
  --resource-group rg-image-resizer \
  --consumption-plan-location westeurope \
  --runtime dotnet-isolated \
  --runtime-version 8 \
  --functions-version 4 \
  --name func-image-resizer-prod \
  --storage-account mystorageaccount

# Create Application Insights
az monitor app-insights component create \
  --app func-image-resizer-insights \
  --location westeurope \
  --resource-group rg-image-resizer \
  --application-type web

# Configure connection strings
az functionapp config appsettings set \
  --name func-image-resizer-prod \
  --resource-group rg-image-resizer \
  --settings \
    StorageConnectionString="YOUR_CONNECTION_STRING" \
    StorageContainerName="images" \
    APPLICATIONINSIGHTS_CONNECTION_STRING="YOUR_APP_INSIGHTS_CONNECTION_STRING"

# Deploy
cd src
func azure functionapp publish func-image-resizer-prod

For detailed deployment instructions, see DEPLOYMENT.md.

🧪 Testing

Run Unit Tests

cd tests
dotnet test

Result: 15/15 tests passed ✅

Endpoint Tests

While the function is running:

# Test 1: Width only
curl "http://localhost:7071/api/test-image.jpg?w=500" -o resized.jpg

# Test 2: Format conversion
curl "http://localhost:7071/api/test-image.jpg?w=300&format=webp" -o resized.webp

# Test 3: Crop mode
curl "http://localhost:7071/api/test-image.jpg?w=300&h=300&mode=crop" -o thumbnail.jpg

📊 Performance

Expected Performance

Scenario Consumption Plan Premium Plan CDN Cache Hit
Cold Start 2-5 seconds <500ms N/A
Warm Request 100-500ms 50-200ms <50ms
Throughput ~100 req/s ~1000 req/s ~10000 req/s

🔍 Monitoring

Application Insights monitors the following metrics:

  • Request rate and response time
  • Failure rate and exceptions
  • Dependency calls (Blob Storage)
  • Custom metrics (image size, format, etc.)
  • Performance counters

View metrics in Azure Portal → Application Insights → Performance.

🔐 Security

Production Recommendations

  1. Change Authorization Level:

    [HttpTrigger(AuthorizationLevel.Function, "get", Route = "{*imagePath}")]
  2. Configure CORS:

    az functionapp cors add --name myImageResizerApp \
      --resource-group myResourceGroup \
      --allowed-origins https://yourdomain.com
  3. Use Managed Identity: Prefer Managed Identity over connection strings for Blob Storage access.

  4. Rate Limiting: Add rate limiting via Azure Front Door WAF policy.

🤝 Contributing

Pull requests are welcome. For major changes, please open an issue first.

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/AmazingFeature)
  3. Commit your changes (git commit -m 'Add some AmazingFeature')
  4. Push to the branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

See CONTRIBUTING.md for details.

📄 License

MIT License - See LICENSE for details.

📞 Support

For questions, please use GitHub Issues.

🙏 Acknowledgments


Developer: Zenigma Dev
Version: 1.0.0
Last Updated: October 10, 2025

About

No description, website, or topics provided.

Resources

License

Contributing

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages