PHP code example of fruitcake / laravel-image-variants
1. Go to this page and download the library: Download fruitcake/laravel-image-variants library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
fruitcake / laravel-image-variants example snippets
use Fruitcake\ImageVariants\Facades\Variants;
// A named preset from the config
Variants::url('img/bg.jpg', 'hero');
// /storage/variants/hero/9a8c70ca57/bg.jpg?src=img/bg.jpg
// Ad-hoc operations, converting to webp
Variants::url('img/bg.jpg', ['cover' => [600, 500], 'quality' => 80], 'webp');
// /storage/variants/custom/b754ff4bfa/bg.webp?src=img/bg.jpg&cover=600,500&quality=80
// A preset, a nicer filename, and one operation added on top
Variants::url('img/bg.jpg', 'thumb', 'webp', 'team-photo', ['grayscale' => true]);
// /storage/variants/thumb/cb20a26822/team-photo.webp?src=img/bg.jpg&grayscale=1
Variants::url(
string $src, // relative to the configured source disk
string|array $preset = 'custom', // a preset name, or operations
?string $format = null, // output extension; defaults to the source's
?string $name = null, // filename to serve as; defaults to the source's
array $operations = [], // merged over the preset
);
'cache_store' => null, // null = default store
'lock' => [
'enabled' => true,
'ttl' => 30, // how long the lock survives a worker that dies holding it
'wait' => 10, // how long a queued request waits before generating anyway
],
use Illuminate\Support\Facades\Schedule;
Schedule::command('image-variants:cleanup')->weekly();