Generate Uploadcare image processing URLs to transform and process your images. No need to write or generate the URL yourself. Just pass the UUID of the file, optionally pass the custom CDN, and chain the methods you want to apply and the package generates the URL for you.
Installation
You can install the package via composer:
composer require vormkracht10/php-uploadcare-transformations
Usage
- Import UploadcareTransformation.
- Get the UUID of the file you want to show.
- Set your CDN url (optional).
- Create the transformation URL by chaining one or multiple methods to the UploadcareTransformation class. You can chain as much methods as you want.
- Use the output of the transformation as image source.
use Vormkracht10\UploadcareTransformations\UploadcareTransformation;
$uuid = '12a3456b-c789-1234-1de2-3cfa83096e25';
$cdnUrl = 'https://example.com/cdn/';
$transformation = (new UploadcareTransformation($uuid, $cdnUrl));
$url = $transformation->crop(width: 320, height: '50p', offsetX: 'center')->setFill(color: 'ffffff');
echo $url;
// https://example.com/cdn/12a3456b-c789-1234-1de2-3cfa83096e25/-/crop/320x50p/center/-/set_fill/ffffff
If you prefer to use a shorter version you can also use the helper method:
$uuid = '12a3456b-c789-1234-1de2-3cfa83096e25';
$cdnUrl = 'https://example.com/cdn/';
$url = uc($uuid, $cdnUrl)
->crop(width: 320, height: '50p', offsetX: 'center')
->setFill(color: 'ffffff')
->getUrl();
echo $url;
// https://example.com/cdn/12a3456b-c789-1234-1de2-3cfa83096e25/-/crop/320x50p/center/-/set_fill/ffffff
Using the Laravel framework
When you are using the Laravel framework it might be better to define the CDN in your .env file and get the value from the .env file in a config file. You can create a dedicated config/uploadcare config or add it to the config/services file.
Your .env file:
UPLOADCARE_CDN=https://example.com/cdn/
Your config/uploadcare.php file:
return [
'cdn' => env('UPLOADCARE_CDN', 'https://ucarecdn.com'),
];
In your code:
$url = uc($uuid, config('uploadcare.cdn'))->crop(width: 320, height: '50p', offsetX: 'center')->setFill(color: 'ffffff');
Available methods
- Adding filename
- Auto rotate
- Basic color adjustments
- Blur
- Blur faces
- Blur region
- Convert to sRGB
- Crop
- Crop by objects
- Crop by ratio
- Enhance
- Filter
- Flip
- Format
- Grayscale
- ICC profile size threshold
For more details, please visit Github.