14
OctGenerate 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.
You can install the package via composer:
composer require vormkracht10/php-uploadcare-transformations
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
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
For more details, please visit Github.
Published at : 14-10-2022
I am a highly results-driven professional with 12+ years of collective experience in the grounds of web application development especially in laravel, native android application development in java, and desktop application development in the dot net framework. Now managing a team of expert developers at Codebrisk.
Launch project