2017 © Pedro Peláez
 

cakephp-plugin image-presenter

A CakePHP plugin for creating thumbnails and image variants on the fly

image

xavier83ar/image-presenter

A CakePHP plugin for creating thumbnails and image variants on the fly

  • Tuesday, February 23, 2016
  • by xavier83ar
  • Repository
  • 1 Watchers
  • 1 Stars
  • 22 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 9 Versions
  • 0 % Grown

The README.md

ImagePresenter plugin for CakePHP

Installation

You can install this plugin into your CakePHP application using composer., (*1)

The recommended way to install composer packages is:, (*2)

composer require xavier83ar/image-presenter

Usage

Load the plugin, (*3)

Plugin::load('ImagePresenter', ['routes' => true]);

Configure your variants..., (*4)

'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., (*5)

This helpers uses imagine/imagine package for image manipulation operations, see https://imagine.readthedocs.org/en/latest/ for more information., (*6)

Showing up images

Finally load and use ImageHelper, (*7)

class AppView extends View
{
    public function initialize()
    {
        $this->loadHelper('ImagePresenter.Image');
    }
}

On your templates, (*8)

<img src="<?= $this->Image->variant($img, 'thumbnail') ?>" alt="">

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., (*9)

This way variants are created only when needed, and only once., (*10)

The Versions

23/02 2016

dev-master

9999999-dev

A CakePHP plugin for creating thumbnails and image variants on the fly

  Sources   Download

MIT

The Requires

 

The Development Requires

23/02 2016

v1.0.7

1.0.7.0

A CakePHP plugin for creating thumbnails and image variants on the fly

  Sources   Download

MIT

The Requires

 

The Development Requires

23/02 2016

v1.0.6

1.0.6.0

A CakePHP plugin for creating thumbnails and image variants on the fly

  Sources   Download

MIT

The Requires

 

The Development Requires

18/02 2016

v1.0.5

1.0.5.0

A CakePHP plugin for creating thumbnails and image variants on the fly

  Sources   Download

MIT

The Requires

 

The Development Requires

18/02 2016

v1.0.4

1.0.4.0

A CakePHP plugin for creating thumbnails and image variants on the fly

  Sources   Download

MIT

The Requires

 

The Development Requires

18/02 2016

v1.0.3

1.0.3.0

A CakePHP plugin for creating thumbnails and image variants on the fly

  Sources   Download

The Requires

 

The Development Requires

18/02 2016

v1.0.2

1.0.2.0

A CakePHP plugin for creating thumbnails and image variants on the fly

  Sources   Download

The Requires

 

The Development Requires

18/02 2016

v1.0.1

1.0.1.0

A CakePHP plugin for creating thumbnails and image variants on the fly

  Sources   Download

The Requires

 

The Development Requires

18/02 2016

v1.0.0

1.0.0.0

A CakePHP plugin for creating thumbnails and image variants on the fly

  Sources   Download

The Requires

 

The Development Requires