aneeskhan47 / php-cloudflare-image-resizing
A PHP package to generate Cloudflare Image Resizing URLs
Fund package maintenance!
www.paypal.com/paypalme/aneeskhan47
Requires
- php: ^8.2.0
Requires (Dev)
- laravel/pint: ^1.10.1
- pestphp/pest: ^2.6.3
- phpstan/phpstan: ^1.10.18
- rector/rector: ^0.15.25
- symfony/var-dumper: ^6.3.0
README
A PHP package to generate Cloudflare Image Resizing URLs. based on Cloudflare Image Resizing.
⚡️ Installation
Requires PHP 8.2+
composer require aneeskhan47/php-cloudflare-image-resizing
❓ How it works
Cloudflare Image Resizing is a feature that allows you to resize, crop, and convert images by simply changing the URL of the image. This is done by adding a set of image transformation parameters to the URL of the image, which Cloudflare will then use to generate a new image on the fly.
So just by adding /cdn-cgi/image/
to the beginning of the URL, you can utilize Cloudflare's image resizing feature.
You can convert and resize images by requesting them via a specially-formatted URL. This way you do not need to write any code, only change HTML markup of your website to use the new URLs.
For more information, please see the Cloudflare Image Resizing documentation.
This package provides a fluent API to generate Cloudflare Image Resizing URLs.
🚀 Usage
Generating a URL without any transformations
use AneesKhan47\CloudflareImageResizing\CFImageResizing; $url = 'https://example.com/uploads/2023/image.jpg'; $image = CFImageResizing::make($url)->build(); // output: // https://example.com/cdn-cgi/image/format=auto/uploads/2023/image.jpg // note: format=auto is added by default to the URL as it is required // by Cloudflare to have atleast one transformation applied.
Generating a URL with transformations
use AneesKhan47\CloudflareImageResizing\CFImageResizing; $url = 'https://example.com/uploads/2023/image.jpg'; $image = CFImageResizing::make($url) ->width(300) ->height(300) ->webp() ->quality(80) ->build(); // output: // https://example.com/cdn-cgi/image/width=300,height=300,format=webp,quality=80/uploads/2023/image.jpg
Available transformations
🧪 Testing
🧹 Keep a modern codebase with Pint:
composer lint
✅ Run refactors using Rector
composer refacto
⚗️ Run static analysis using PHPStan:
composer test:types
✅ Run unit tests using PEST
composer test:unit
🚀 Run the entire test suite:
composer test
📝 Changelog
Please see CHANGELOG for more information on what has changed recently.
🤝 Contributing
Please see CONTRIBUTING for details.
🔒 Security
If you discover any security-related issues, please email kingkhan2388@gmail.com instead of using the issue tracker.
🙌 Credits
📜 License
The MIT License (MIT). Please see License File for more information.
🔧 Skeleton PHP Boilerplate
This package was generated using the Skeleton PHP by Nuno Maduro.