PHP code example of jeffersongoncalves / laravel-image-cache
1. Go to this page and download the library: Download jeffersongoncalves/laravel-image-cache 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/ */
jeffersongoncalves / laravel-image-cache example snippets
$cache = new ImageCache(disk: 'public', pathPrefix: 'og-images', ttlSeconds: 86400);
$cache->warm('project-42', $untrustedImageUrl);
return [
'timeout' => (int) env('IMAGE_CACHE_TIMEOUT', 8),
'max_redirects' => (int) env('IMAGE_CACHE_MAX_REDIRECTS', 3),
];
use JeffersonGoncalves\ImageCache\ImageCache;
$cache = new ImageCache(disk: 'public', pathPrefix: 'og-images', ttlSeconds: 86400);
$cache->warm(key: 'project-42', url: $project->social_image);
use JeffersonGoncalves\SsrfGuard\SsrfGuard;
$resolve = app(SsrfGuard::class)->resolveEntries($url);
if ($resolve !== null) {
$cache->warm('project-42', $url, $resolve);
}
$image = $cache->get('project-42');
// ['body' => '<binary>', 'type' => 'image/png'] or null if never warmed successfully
public function show(string $slug)
{
return $cache->response($slug) ?? abort(404);
}
bash
php artisan vendor:publish --tag="image-cache-config"