Download the PHP package marceli-to/intervention-image-cache without Composer
On this page you can find all versions of the php package marceli-to/intervention-image-cache. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download marceli-to/intervention-image-cache
More information about marceli-to/intervention-image-cache
Files in marceli-to/intervention-image-cache
Package intervention-image-cache
Short Description A simple image caching package for Intervention Image v3
License MIT
Informations about the package intervention-image-cache
Intervention Image Cache
A simple image caching package for Laravel using Intervention Image v3.
Installation
You can install the package via composer:
Intervention Image v3 Compatibility
This package is built for Intervention Image v3, which has a significantly different API compared to v2. If you're upgrading from a package that used Intervention Image v2, please note these key differences:
- The v3 API uses interfaces like
ImageInterfaceandModifierInterface - Image manipulation methods return a new image instance rather than modifying the original
- The driver system has changed (GD is used by default in this package)
For more details on Intervention Image v3, please refer to the official documentation.
Configuration
Publish the configuration file:
This will create a config/image-cache.php file where you can configure:
- Cache path
- Cache lifetime
- Image search paths
- Available templates
- Route configuration
Usage
Basic Usage
In a Controller
In Views
The package automatically registers the necessary routes, so you can use it directly in your views:
The URL format is:
Where:
template: One of the templates defined in your config (e.g., 'large', 'small', 'thumbnail', 'crop')filename: The name of the image file to processmaxWidth: (Optional) Maximum width for the output imagemaxHeight: (Optional) Maximum height for the output imagecoords: (Optional) Comma-separated string in the formatx,y,width,heightfor cropping
Important notes about cropping coordinates:
- All four values must be numeric
- x and y coordinates must be non-negative (values less than 0 will be set to 0)
- Width and height must be positive (values less than or equal to 0 will skip cropping)
- Coordinates that exceed image dimensions will be adjusted automatically
- If all coordinates are 0 (0,0,0,0), cropping will be skipped
Custom Controller
If you prefer to use your own controller, you can disable the automatic route registration in the config file:
Then create your own route and controller:
Programmatic Usage
You can also use the package programmatically:
Clearing the Cache
You can clear the cache using the provided Artisan command:
Or programmatically:
Custom Templates
You can create your own templates by:
- Creating a class that implements
Intervention\Image\Interfaces\ModifierInterface - Registering it in the
templatesarray in the config file
Example:
Then in your config:
Using Cropping in Custom Templates
You can implement cropping in your custom templates by following this pattern:
Testing
The package includes a comprehensive test suite. To run the tests:
Or you can run PHPUnit directly:
The test suite includes:
- Unit tests for template classes
- Unit tests for the ImageCache class
- Feature tests for the HTTP endpoints
License
The MIT License (MIT).
All versions of intervention-image-cache with dependencies
intervention/image Version ^3.0
illuminate/support Version ^10.0|^11.0
illuminate/filesystem Version ^10.0|^11.0