PHP code example of marceli-to / intervention-image-cache
1. Go to this page and download the library: Download marceli-to/intervention-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/ */
marceli-to / intervention-image-cache example snippets
use MarceliTo\InterventionImageCache\Facades\ImageCache;
// Get a cached image
$path = ImageCache::getCachedImage('large', 'image.jpg');
// Display the image in a view
<img src="{{ asset('storage/cache/images/' . basename($path)) }}" alt="Image">
use MarceliTo\InterventionImageCache\Facades\ImageCache;
class ImageController extends Controller
{
public function show($template, $filename)
{
$path = ImageCache::getCachedImage($template, $filename);
if (!$path) {
abort(404);
}
return response()->file($path);
}
}
use MarceliTo\InterventionImageCache\Facades\ImageCache;
// Get a cached image
$path = ImageCache::getCachedImage('large', 'image.jpg', [
'maxWidth' => 1200,
'maxHeight' => 800
]);
// Get a cached image with cropping
$path = ImageCache::getCachedImage('crop', 'image.jpg', [
'maxWidth' => 800,
'maxHeight' => 600,
'coords' => '100,150,500,300' // Format: x,y,width,height
]);
use MarceliTo\InterventionImageCache\Facades\ImageCache;
// Clear all cached images
ImageCache::clearCache();
// Clear cached images for a specific template
ImageCache::clearTemplateCache('large');
namespace App\ImageTemplates;
use Intervention\Image\Interfaces\ImageInterface;
use Intervention\Image\Interfaces\ModifierInterface;
class Custom implements ModifierInterface
{
public function apply(ImageInterface $image): ImageInterface
{
return $image->resize(500, 500);
}
}