GenticsImageStore PHP

1 Settings


'modules' => array(
    'genticsimagestore' => array(
        'class' => 'common.modules.genticsimagestore.GenticsImageStoreModule',
        'imageDriver' => "imagick",
        'cache' => array(
            'folder'         => null,
            'maxAge'         => 0,
            'maxSize'        => 0,
            'instantCleanup' => true,
        ),
        'onDemandResize' => false,
        'onDemandFileEnding' => '.info'
    )
)

1.1 imageDriver

Can be either set to “imagick” or “gd”. If you set this to “imagick” and the PHP “Imagick” class is not available it will switch to “gd” automatically.

1.2 cache

1.2.1 folder

The directory where the cache files will be written. This can either be a string to specify the path, or null to automatically create a “GenticsImageStore” directory in the DCR or FSCR folder (depending on which one is used).

This directory needs to be read and writable by the webserver and PHP user.

1.2.2 maxAge

Can be 0 if you never want to delete old files or an integer value that specifies the max age in seconds. Example: 604800 to keep cache files for 1 week.

1.2.3 maxSize

Can be 0 if the total size of the cache folder doesn’t matter, otherwise this specifies the number of bytes the cache folder can have: Example: 10737418240 to allow the cachefolder to have 10 GB.

1.2.4 instantCleanup

When this is set to true, the image cache will be cleaned up instantly everytime, before the first image in a page is resized. However, if you plan to resize more than ~10.000 images you should set this to false and use a cronjob for cache clearing instead, that calls the cleanupCache command on the shell.

1.3 onDemandResize

When this is set to true, the images will be cropped and resized on the first request to the image.

1.4 onDemandFileEnding

This is the file ending of the images containing the information for the on demand resized images.

2 Widget

The widget is the most powerful part of this module and allows you to easily resize any amount of images in your pages. See the GenticsImageStoreWidget documentation

3 Module

Images can also be resized without using the widget, in case you want to do more advanced things with image resizing:


$genticsImageStoreModule = Yii::app()->getModule('genticsimagestore');
$url = genticsImageStoreModule-> = $genticsImageStoreModule->transformImageByRepositoryId(
    185, $yourResizeOptions, $yourCropOptions, "/Content.Node/image.png");

More public methods can be found in the class GenticsImageStoreModule.

3.1 Caching

The GenticsImageStoreModule has an automatic cache management mechanism, to ensure that the total cache size doesn’t exceed the limits of the host system (see the settings), but also to make sure that images are resized automatically again, if the original source image changes. This is accomplised by comparing the modification timestamps of the original and the resized image file. However this only works for files that exist on the local filesystem (DCR cache, other local files), not for HTTP, FTP or any other remote URLs.

A cache file will look like the following:


7ce1df27155ac9e97ca29bb1a605949a-mybeautifulimage.jpg

4 Console commands

It is important to also add the module settings in client_console.php, otherwise these console commands won’t work

  • yiic genticsimagestore clearCache
  • yiic genticsimagestore cleanupCache

4.1 clearCache

  • Calls GenticsImageStoreModule::clearCache()
  • Deletes all cache files

4.2 cleanupCache

  • Calls GenticsImageStoreModule::clearCache()
  • Deletes expired cache files or old files to shrink the total cache size
  • If you have allot of files, you should disable the setting “instantCleanup” and call this command in a certain time intervall using a cronjob