Automated S3 Image Compression and Watermarking

Job ID: 38737514

Budget: ₹600 – ₹1,500 INR

Title:
Image Compression and Watermarking for Automatic S3 Processing

As a
marketing team member or developer responsible for managing and distributing media assets,

I want
an automated image processing service that reduces the size of large images and applies a watermark before they’re stored in a designated S3 bucket,

So that
I can streamline our image management, ensuring consistent file sizes and brand-specific watermarks for easy sharing and use across various platforms.

Acceptance Criteria
Trigger on Image Upload:

Given that a new image file is uploaded to the source S3 bucket,
When the upload is completed,
Then the Lambda function is triggered automatically to start processing the image.
Image Compression and Resizing:

Given the uploaded image,
When the Lambda function processes the image,
Then it resizes the image to a predefined dimension (e.g., 800x600) and compresses it to a specified quality level (e.g., 80%).
Watermark Application:

Given that the image has been resized and compressed,
When watermark settings are enabled,
Then the function applies a customizable watermark, which can either be text-based (with options for font size, position, and opacity) or image-based (with options for position, opacity, and scaling).
Save Processed Image to Destination Bucket:

Given the image has been processed,
When the function completes all processing steps,
Then it saves the watermarked and compressed image to a designated “processed” S3 bucket with a unique path (e.g., processed/original_filename).
Metadata and Success Feedback:

Given that the image processing and upload are successful,
When the image is saved in the processed bucket,
Then the Lambda function logs details such as the original filename, processed file size, and S3 path in CloudWatch logs and returns a 200 status code with confirmation.
Error Handling and Logging:

Given any error in the processing steps (e.g., unsupported file format or S3 access error),
When the function encounters an issue,
Then it logs the error in CloudWatch, sends an error response with relevant details, and gracefully exits without processing further.
Detailed Requirements
Processing Specifications

Input Image Size: Support various sizes, with logic to resize if an image exceeds certain dimensions.
Output Quality: Maintain a balance between quality and file size, targeting an 80% compression quality.
Image Formats: Accept and process common image formats, including JPEG and PNG.
Watermark Customization Options

Text Watermark Options:
Font Size: Adjustable based on environment variable (default: 20).
Position: Customizable (e.g., bottom-right corner).
Opacity: Set via environment variable to control watermark visibility (default: 128).
Image Watermark Options:
Scale: Allows scaling watermark size relative to the base image (default: 30%).
Opacity: Set via environment variable for transparency.
Lambda Environment Configurations

Environment Variables: Define settings such as watermark text, quality percentage, and dimensions without code changes.
S3 Bucket Configuration

Source Bucket: Trigger on PUT events for new uploads.
Destination Bucket: Store processed images in a separate S3 path (processed/).
Technical Constraints
AWS Lambda Limitations: Ensure memory usage and execution time stay within Lambda’s constraints.
Image Processing: Use efficient libraries like Pillow for in-memory processing to reduce I/O time.
Storage Costs: Ensure processed images are optimized to minimize S3 storage and transfer costs.
Priority and Milestones

MVP: Automated image compression and resizing for new uploads to the source bucket.
Watermarking: Add both text and image watermarking options.
Error Handling and Logging: Comprehensive error management and logging.
Related categories: Python Docker