Overview
Stormkit includes a powerful, framework-agnostic image optimization feature that allows you to resize and crop images on-the-fly through simple URL parameters. This feature helps improve your website’s performance by delivering appropriately sized images to your users. The image optimization service automatically processes images when specific query parameters are detected in the image URL. Optimized images are cached for improved performance on subsequent requests.Usage
To optimize an image, simply add query parameters to your image URL:Parameters
Examples
Basic Resize
Resize maintaining aspect ratioResizes to 400px width while maintaining aspect ratio.
Specific Dimensions
Force exact dimensionsForces image to be exactly 400px × 300px.
Smart Cropping
Intelligent focus preservationCrops to 400x300px while focusing on important parts.
Responsive Images
Different sizes for different devices
Use Cases
Responsive Images
Use different size parameters based on the user’s device to deliver appropriate images:Thumbnails with Smart Cropping
When creating thumbnails or profile pictures, use smart cropping to ensure the subject remains in focus:Gallery Optimization
Security and Limitations
Why These Limits?
- Maximum dimensions prevent abuse and ensure reasonable resource usage
- Variant limit prevents storage exhaustion from unlimited optimization requests
- Caching improves performance for subsequent requests
Additional variant requests beyond the 5-variant limit will return the original image.
Best Practices
1. Use Appropriate Sizes
Don’t request images larger than you need:2. Leverage Smart Cropping
Use smart cropping for thumbnails and profile pictures:3. Implement Responsive Images
Serve different sizes for different screen sizes:4. Plan Your Variants
With a 5-variant limit, choose your sizes wisely:Supported Formats
The image optimization service supports the following formats:- JPEG - Best for photographs
- PNG - Best for graphics with transparency
- WebP - Modern format with excellent compression
- GIF - Non-animated GIFs only
- TIFF - High-quality images
Animated GIFs are not supported. The first frame will be used.
Error Handling
If an image cannot be optimized due to any reason (invalid image format, processing error, etc.), the system will return the original image without optimization. This ensures your site never breaks due to image optimization failures.Performance Tips
Pre-warm Cache
Request common image sizes during deployment to pre-warm the cache.
CDN Integration
Optimized images work seamlessly with CDNs for global distribution.
Lazy Loading
Combine with lazy loading for optimal page load performance.
Monitor Usage
Track which variants are actually used and adjust accordingly.
Troubleshooting
Image not resizing
Image not resizing
- Verify the size parameter format is correct
- Check if the image format is supported
- Ensure the URL is properly encoded
- Verify the domain has optimization enabled
Getting original image instead of optimized
Getting original image instead of optimized
- Check if you’ve exceeded the 5-variant limit
- Verify dimensions don’t exceed 2048px
- Check if the image format is supported
- Review server logs for processing errors
Smart cropping not working as expected
Smart cropping not working as expected
- Ensure smart=true parameter is set
- Verify both width and height are specified
- Remember: smart cropping analyzes image content
- Try different size ratios for better results