alexbuckham / cloudflare-images-laravel
Provides access to the Cloudflare Images service for Laravel.
0.0.1
2022-01-02 02:12 UTC
Requires
- php: ^7.4|^8.0
- guzzlehttp/guzzle: ^7.0
- illuminate/contracts: ^8.0
Requires (Dev)
- orchestra/testbench: ^6.0
- phpunit/phpunit: ^9.3
This package is auto-updated.
Last update: 2024-10-15 04:01:35 UTC
README
Provides access to Cloudflare Images service for Laravel.
Table of contents
Installation
To get the latest version of CloudflareImagesLaravel
, simply require the project using Composer:
composer install alexbuckham/cloudflare-images-laravel
Or manually update the require
block of composer.json
and run composer update
.
{ "require": { "alexbuckham/cloudflare-images-laravel": "^0.0.1" } }
Configuration
Set environment variables:
CF_IMAGES_ACCOUNT_ID
- Cloudflare account IDCF_IMAGES_CF_IMAGES_TOKEN
- Cloudflare API tokenCF_IMAGES_KEY
- Create a CF images key under the Images section of your Cloudflare accountCF_IMAGES_DELIVERY_URL
- Copy the images delivery base url from the Cloudflare images dashboard
Usage
Create a variant
use AlexBuckham\CloudflareImagesLaravel\CloudflareImages; use AlexBuckham\CloudflareImagesLaravel\ImageVariant; $variant = new ImageVariant('tiny'); $variant->fit('contain') ->width(50) ->height(50) ->metaData('keep'); $cfImages = new CloudflareImages(); $cfImages->createVariant($variant);
Upload an image
use AlexBuckham\CloudflareImagesLaravel\CloudflareImages; $cfImages = new CloudflareImages(); // Pass either a file path or a file resource as the first parameter. // If you want the image to be private (always require signed urls), pass true as the second parameter. $cfImages->upload('/path/to/image.jpg', true);
Generate a signed URL
use AlexBuckham\CloudflareImagesLaravel\CloudflareImages; $cfImages = new CloudflareImages(); $cfImages->getSignedUrl('image-uuid', new DateTime('+1 day'));
Overriding configuration
You can override the environment variables by passing new properties to the CloudflareImages
constructor.
use AlexBuckham\CloudflareImagesLaravel\CloudflareImages; $cfImages = new CloudflareImages('CF_IMAGES_ACCOUNT_ID', 'CF_IMAGES_CF_IMAGES_TOKEN', 'CF_IMAGES_KEY', 'CF_IMAGES_DELIVERY_URL');