PHP code example of tempest / responsive-image

1. Go to this page and download the library: Download tempest/responsive-image 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/ */

    

tempest / responsive-image example snippets


use Tempest\ResponsiveImage\ResponsiveImageFactory;
use Tempest\ResponsiveImage\ResponsiveImageConfig;

$config = new ResponsiveImageConfig(
    srcPath: __DIR__ . '/path/to/image/sources',
    publicPath: __DIR__ . '/../public',
);

$imageFactory = new ResponsiveImageFactory($config);

$image = $imageFactory->create('/parrot.jpg');

echo $image->html;

// <img src="/parrot.jpg" srcset="/parrot-1920-1280.jpg 1920w, /parrot-1606-1070.jpg 1606w, /parrot-1214-809.jpg 1214w, /parrot-607-404.jpg 607w">