Fluent API for Cloudflare Image Transformations.
Requires PHP 8.3+ and Laravel 12+.
composer require gwhthompson/laravel-cloudflare-transformsSet your disk's url to a Cloudflare-proxied domain:
// config/filesystems.php
'media' => [
'driver' => 's3',
'url' => env('CLOUDFLARE_CDN_URL'), // https://cdn.example.com
// ...
],A url mounted at a sub-path (e.g. the default public disk at
APP_URL/storage) works too: the sub-path is folded into the transform
source path, which Cloudflare resolves from the zone root.
Storage::disk('media')->cloudflareImage('photo.jpg')
->width(400)
->format(Format::Auto)
->url();
// → https://cdn.example.com/cdn-cgi/image/w=400,f=auto/photo.jpg
// Responsive srcset
Storage::disk('media')->cloudflareImage('hero.jpg')
->srcset([320, 640, 960, 1280]);
// Convenience methods
->optimize() // format=auto, quality=high
->thumbnail(150) // square crop
->grayscale()<x-cloudflare:image
path="hero.jpg"
:width="1200"
:fit="Fit::Cover"
:srcset="[320, 640, 960, 1280]"
sizes="(max-width: 640px) 100vw, 50vw"
onerror="redirect"
/>| Enum | Values |
|---|---|
Fit |
Contain, Cover, Crop, Pad, ScaleDown, Squeeze |
Format |
Auto, Avif, Jpeg, Webp |
Quality |
High, MediumHigh, MediumLow, Low |
Gravity |
Auto, Top, Bottom, Left, Right, Face |
php artisan vendor:publish --tag=cloudflare-transforms-config| Option | Default | Purpose |
|---|---|---|
domain |
null |
Fallback for CloudflareImage::make() |
transform_path |
cdn-cgi/image |
Custom path with URL rewrite |
validate_file_exists |
true |
Disable for performance |
# .env.testing
CLOUDFLARE_VALIDATE_FILE_EXISTS=falseReport vulnerabilities to security@unfetter.co.
MIT