devfactory / imagecache
Laravel package for generating thumbnails of images and caching them in your public files folder.
Installs: 16 987
Dependents: 1
Suggesters: 0
Security: 0
Stars: 16
Watchers: 6
Forks: 9
Open Issues: 1
Requires
- php: >=5.4.0
- illuminate/support: ^5.0|^6.0|^7.0|^8.0|^9.0|^10.0|^11.0
- intervention/image: ~2.1
This package is auto-updated.
Last update: 2024-12-18 14:56:09 UTC
README
Imagecache
Laravel 4/5 package that allows you to create image thumbnails according to predefined presets, and store them in your Laravel public folder to serve them up without generating them on each page load.
Installation
Using Composer, edit your composer.json
file to require devfactory/imagecache
.
Laravel 5
"require": {
"devfactory/imagecache": "3.0.*"
}
Laravel 4
"require": {
"devfactory/imagecache": "2.1.*"
}
Then from the terminal run
composer update
Then in your app/config/app.php
file register the following service providers:
'Intervention\Image\ImageServiceProvider', 'Devfactory\Imagecache\ImagecacheServiceProvider',
And the Facade:
'Imagecache' => 'Devfactory\Imagecache\Facades\ImagecacheFacade',
Publish the config:
Laravel 5
php artisan vendor:publish
Laravel 4
php artisan config:publish devfactory/imagecache
Usage
Define some presets in:
Laravel 5
config/imagecache.presets.php
Laravel 4
app/config/packages/devfactory/imagecache/presets.php
<?php return array( 'teaser' => array( 'width' => 150, 'height' => 100, 'method' => 'crop', ), '465x320' => array( 'width' => 465, 'height' => 320, 'method' => 'resize', 'background_color' => '#FFFFFF', ), );
get($filename, $preset, $args = NULL)
$args properties
Return Value:
Example usages:
$image = Imagecache::get('images/sunset.jpg', 'teaser'); echo $image->img; echo '<img src="'. $image->src .'"> // Directly in a blade template {{ Imagecache::get('uploads/images/sunset.jpg', 'teaser')->img }}
You can also directly access one of the properties as such without needing to if gate the call to get()
. If using Laravel 5 you'll need to use the new raw notation instead of the double curly braces {{ ... }}
.
{!! Imagecache::get('uploads/images/sunset.jpg', 'teaser')->img !!}
If you set the use_placeholders
variable to TRUE
in the imagecache.config.php
file, and your image doesn't exist or doesn't generate a cached version. Where you would normally receive an array with empty values, you can get a placeholder image matching the preset that you requested. This is very useful during developement when you might not have images for all your content.
get_original($filename, $args = NULL)
If you don't want to apply any preset to the image, but still want to use the call to generate the <img>
tag, accepts same parameters and works the same way as get()
, just without $preset
delete($filename)
Deletes all the cached images for each preset for the given filename.
Presets
When defining your presets, these are the options you can set:
The method
property accepts the following types of transformations: