https://github.com/xavier83ar/image-presenter
A CakePHP plugin for creating thumbnails and image variants on the fly
https://github.com/xavier83ar/image-presenter
cakephp cakephp-plugin helper image image-processing thumbnails
Last synced: 26 days ago
JSON representation
A CakePHP plugin for creating thumbnails and image variants on the fly
- Host: GitHub
- URL: https://github.com/xavier83ar/image-presenter
- Owner: xavier83ar
- License: mit
- Created: 2016-02-17T02:13:12.000Z (over 10 years ago)
- Default Branch: master
- Last Pushed: 2016-02-23T22:16:29.000Z (over 10 years ago)
- Last Synced: 2025-12-14T18:18:30.611Z (6 months ago)
- Topics: cakephp, cakephp-plugin, helper, image, image-processing, thumbnails
- Language: PHP
- Size: 1.34 MB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# ImagePresenter plugin for CakePHP
## Installation
You can install this plugin into your CakePHP application using [composer](http://getcomposer.org).
The recommended way to install composer packages is:
```
composer require xavier83ar/image-presenter
```
## Usage
Load the plugin
```php
Plugin::load('ImagePresenter', ['routes' => true]);
```
Configure your variants...
```php
'ImagePresenter' => [
'variants' => [
'thumbnail' => [
'size' => [350, 250],
'mode' => ImageInterface::THUMBNAIL_OUTBOUND,
'filter' => ImageInterface::FILTER_LANCZOS
],
'mini' => [
'operation' => 'thumbnail',
'size' => [120, 120],
'mode' => ImageInterface::THUMBNAIL_INSET,
],
'other' => [
'operation' => function (ImageInterface $imagine) {
return $imagine->resize(new Box(400, 300))->rotate(90);
}
],
'amazing' => [
'operation' => function (ImageInterface $imagine) {
return $imagine
->resize(new Box(600, 320))
->effects()->grayscale()->blur(5);
}
],
],
]
```
Any variant which its name starts with "thumbnail" will use thumbnail operation mode. Right now there two operation modes:
thumbnail, which sets up a `ImageInterface::thumbnail()` operation, and closure mode, which allows you to pass a
closure which receive an `ImageInterface` to play with.
This helpers uses imagine/imagine package for image manipulation operations, see https://imagine.readthedocs.org/en/latest/
for more information.
### Showing up images
Finally load and use ImageHelper
```php
class AppView extends View
{
public function initialize()
{
$this->loadHelper('ImagePresenter.Image');
}
}
```
On your templates
```php
```
`ImagePresenter\View\Helper\ImageHelper::variant()` method will only check if exists a file for that variant, if it does, then it will return the path to that file relative to webroot, if not, it will return the path to the `PresenterController` which takes care of generate that variant and serve the file.
This way variants are created only when needed, and only once.