1. Go to this page and download the library: Download tomkirsch/superimage 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/ */
tomkirsch / superimage example snippets
namespace Config;
class SuperImage extends \Tomkirsch\SuperImage\SuperImageConfig
{
public string $sourcePath = WRITEPATH . 'img/'; // where your hires assets live
public string $cachePath = FCPATH . '_superimage_cache/'; // MUST be in public for direct Apache caching (no PHP overhead)
public string $servingStrategy = 'htaccess'; // most efficient. falls back to php's readfile()
public string $publicUrlPrefix = 'img/';
public string $defaultOutputExt = 'webp';
public bool $enableCacheBusting = true;
public string $cacheBustingMethod = 'mtime'; // use mtime so updated images get automatically stale
}
public static function superImage(?array $options = null, ?SuperImageConfig $config = null): \Tomkirsch\SuperImage\SuperImage
{
$config = $config ?? new \Config\SuperImage();
$instance = new \Tomkirsch\SuperImage\SuperImage($config);
if (!empty($options)) {
$instance->load($options);
}
return $instance;
}
public static function resizer(?SuperImageConfig $config = null): \Tomkirsch\SuperImage\Resizer
{
$config = $config ?? new \Config\SuperImage();
return new \Tomkirsch\SuperImage\Resizer($config);
}
/**
* Serve image request
*/
public function serveImage(...$path)
{
$path = implode("/", $path);
\Config\Services::resizer()->serve($path);
}
'src' => 'hero.jpg' // relative base name with extension
'src' => 'product_1.jpg' // relative base name with extension
'src' => 'products/photo_1.png' // relative base name with subdirectory and extension