Skip to content

alinclaudiu/cakephp-thumber

 
 

Repository files navigation

Thumber

Software License Build Status Build status codecov CodeFactor

cakephp-thumber is a CakePHP plugin to create thumbnails.

It uses intervention/image and provides:

  • ThumbCreator, an utility to create thumbnails;
  • ThumbHelper, a convenient helper that allows you to create thumbnails on the fly from your templates.

Starting from 1.8.0 release, much of the code has been moved into the php-thumber package, so that it becomes a php library independent from CakePHP. This plugin continues to exist and all classes and methods remain unchanged, but it only includes the code closely related to CakePHP (commands, helpers, middlewares, etc). The namespace prefix is now Thumber\Cake and no longer Thumber.

Did you like this plugin? Its development requires a lot of time for me. Please consider the possibility of making a donation: even a coffee is enough! Thank you.

Make a donation


Requirements and supported formats

cakephp-thumber requires GD Library (>=2.0) or Imagick PHP extension (>=6.5.7). It's highly preferable to use Imagick, because It provides better performance and a greater number of supported formats.

Supported formats may vary depending on the library used.

JPEG PNG GIF TIF BMP ICO PSD
GD Yes Yes Yes No No No No
Imagick Yes Yes Yes Yes Yes Yes Yes

For more information about supported format, please refer to the Intervention Image documentation.

Installation

You can install the plugin via composer:

$ composer require --prefer-dist mirko-pagliai/cakephp-thumber

NOTE: the latest version available requires at least CakePHP 4.

Instead, the cakephp3 branch is compatible with all previous versions of CakePHP from version 3.2. This branch coincides with the current version of cakephp-thumber.

In this case, you can install the package as well:

$ composer require --prefer-dist mirko-pagliai/cakephp-thumber:dev-cakephp3

Then you have to load the plugin. For more information on how to load the plugin, please refer to the Cookbook.

Simply, you can execute the shell command to enable the plugin:

bin/cake plugin load Thumber

This would update your application's bootstrap method.

By default the plugin uses the APP/tmp/thumbs directory to save the thumbnails. So you have to create the directory and make it writable:

$ mkdir tmp/thumbs && chmod 775 tmp/thumbs

If you want to use a different directory, read below.

Configuration

The plugin uses some configuration parameters and you can set them using the \Cake\Core\Configure class, before loading the plugin.

For example, you can do this at the bottom of the file APP/config/app.php of your application.

Configuration values

Configure::write('Thumber.driver', 'imagick');

Setting Thumber.driver, you can choose which driver to use for the creation of thumbnails. Valid values are imagick or gd.

Configure::write('Thumber.target', TMP . 'thumbs');

Setting Thumber.target, you can use another directory where the plugin will save thumbnails.

How to use

See our wiki:

And refer to our API.

Testing

The library (GD or Imagick) to be tested is set by the tests/bootstrap.php file, using the THUMBER_DRIVER environment variable. By default, Imagick is used.

For example:

if (!getenv('THUMBER_DRIVER')) {
    putenv('THUMBER_DRIVER=imagick');
}

Configure::write('Thumber.driver', getenv('THUMBER_DRIVER'));

Moreover, some tests belong to the imageEquals group. These tests generate thubnails and compare them with pre-loaded thumbnails (inside tests/comparing_files/). By default, these tests are not performed, because the images may be different if generated from different environments and systems.

To exclude these tests, you should run:

vendor/bin/phpunit --exclude-group imageEquals

Versioning

For transparency and insight into our release cycle and to maintain backward compatibility, Thumber will be maintained under the Semantic Versioning guidelines.

About

cakephp-thumber is a CakePHP plugin to create thumbnails

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors

Languages

  • PHP 100.0%