Prefer to read instead of watch? Here you go! https://aaronfrancis.com/2025/a-cookieless-cache-friendly-image-proxy-in-laravel-inspired-by-cloudflare-9e95f7e0.
In this video I built a very basic version of Cloudflare's image proxy that we use on our various sites, like highperformancesqlite.com. It's a single controller in our Laravel application!
Cloudflare Images: https://www.cloudflare.com/developer-platform/products/cloudflare-images/
Intervention: https://image.intervention.io/v3
Follow me:
Twitter: https://twitter.com/aarondfrancis
LinkedIn: https://www.linkedin.com/in/aarondfrancis
Website: https://aaronfrancis.com - find articles, podcasts, courses, and more.
Chapters:
00:00 - What we’re building: Cloudflare-style image transforms in Laravel
00:59 - Defining the route with dynamic options and path
02:41 - Writing regex constraints for the route
03:56 - Creating the image controller
05:01 - Verifying the image exists
06:40 - Installing and using Intervention Image
07:15 - Parsing the options from the URL
08:45 - Transforming options into a usable array
09:13 - Scaling and manipulating the image
10:00 - Supporting format and quality options
11:58 - Encoding the image with format and quality
13:17 - Returning the image with proper headers
14:49 - Adding cache-control headers for CDN caching
15:59 - Preventing cookies from disabling CDN caching
18:59 - Creating middleware to strip cookies
20:56 - Implementing simple rate limiting
22:32 - Gracefully handling rate limit errors
24:07 - Wrapping up: why this approach works for us