PHP code example of firstinternet / wordpress-responsive-image
1. Go to this page and download the library: Download firstinternet/wordpress-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/ */
firstinternet / wordpress-responsive-image example snippets
use FirstInternet\ResponsiveImage;
$image = new ResponsiveImage(123, 'medium');
$image->generate();
$image = new ResponsiveImage(123, 'large');
$image->setClass('custom-class')
->setAlt('An example image')
->lazyLoad()
->webp()
->generate();
$imageMarkup = (new ResponsiveImage(123, 'full'))->get();
echo $imageMarkup;
$image->setSources([
'sm' => 'small-image',
'md' => 'medium-image',
'lg' => 'large-image'
]);
$image->lazyLoad('custom-lazy-class');
$image->webp();
$image->setClass('img-fluid rounded');
$image->setAlt('Descriptive alt text');
$image->setAttributes([
['data-example', 'value'],
['aria-hidden', 'true']
]);
$image->setSizes('(max-width: 600px) 100vw, 50vw');
$image->autoSizes('col-md-6 col-lg-4');