Skip to content

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Repository files navigation

Laravel Cloudflare Transforms

Tests codecov Latest Version License Total Downloads PHP Version

Fluent API for Cloudflare Image Transformations.

Installation

Requires PHP 8.3+ and Laravel 12+.

composer require gwhthompson/laravel-cloudflare-transforms

Set 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.

Usage

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()

Blade Component

<x-cloudflare:image
    path="hero.jpg"
    :width="1200"
    :fit="Fit::Cover"
    :srcset="[320, 640, 960, 1280]"
    sizes="(max-width: 640px) 100vw, 50vw"
    onerror="redirect"
/>

Enums

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

Configuration

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

Testing

# .env.testing
CLOUDFLARE_VALIDATE_FILE_EXISTS=false

Security

Report vulnerabilities to security@unfetter.co.

License

MIT

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages