sfili81 / image-converter
first extension
Installs: 21
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 1
Forks: 0
Open Issues: 0
Type:yii2-extension
Requires
- yiisoft/yii2: ~2.0.0
README
#Image converter on the fly
==========================
This widget generates (if note exist) images with extension webp and avif.
Installation
The preferred way to install this extension is through composer. Either run
php composer.phar require --prefer-dist sfili81/image-converter "*"
or add
"sfili81/image-converter": "*"
to the require section of your composer.json
file.
##Usage Once the extension is installed, simply use it in your code by :
use sfili81\ImgConverter\ImgConverter; //.. echo ImgConverter::widget(['src'=>'/path/to/image/image.jpg', 'options'=>['class' => 'my-css-class', 'alt' => 'My Image']]);
This will generate :
<picture> <source type="image/avif" srcset="/path/to/image/image.avif"> <source type="image/webp" srcset="/path/to/image/image.webp"> <img class="my-css-class" src="/path/to/image/image.jpg" alt="My Image"> </picture>
You can pass .png
or .jpg
file to the widget. If you pass a .webp
or .avif
image the widget skip the image generation and return the following code:
<img class="my-css-class" src="/path/to/image/image.avif" alt="My Image">