PHP code example of rezozero / slir

1. Go to this page and download the library: Download rezozero/slir library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

rezozero / slir example snippets


namespace MyBundle\Utils;

/**
 * SLIR Config Class
 *
 * @since 2.0
 * @author Joe Lencioni <[email protected]>
 * @package SLIR
 */
class SLIRConfig extends \SLIR\SLIRConfigDefaults
{
  public static function init()
  {
    static::$garbageCollectDivisor =               400;
    static::$garbageCollectFileCacheMaxLifetime =  345600;
    static::$browserCacheTTL  =                    604800; // 7*24*60*60
    static::$pathToCacheDir =                      YOUR_PROJECT_ROOT.'/cache';
    static::$pathToErrorLog =                      YOUR_PROJECT_ROOT.'/files/slir-error-log';
    static::$documentRoot =                        YOUR_PROJECT_ROOT.'/files';
    static::$urlToSLIR =                           '/assets'; // Tell SLIR to listen after "/assets" route
    static::$maxMemoryToAllocate =                 64;
    // This must be the last line of this function
    parent::init();
  }
}

SLIRConfig::init();

#
# routes.yml
#
SLIRProcess:
    path:     /assets/{queryString}/{filename}
    defaults: { _controller: \MyBundle\Controllers\AssetsController::slirAction }
    

// In AssetsController.php class
/**
 * Handle images resize with SLIR vendor
 *
 * @param  string $queryString
 * @param  string $filename
 * @return void
 */
public function slirAction($queryString, $filename)
{
  define('SLIR_CONFIG_CLASSNAME','\MyBundle\Utils\SLIRConfig');

  $slir = new \SLIR\SLIR();
  $slir->processRequestFromURL();

  // SLIR handle response by itself
  // Do not return anything
}