aeYoull / image_retriever
适用于 PrestaShop 的图片检索器
dev-main
2024-02-15 10:31 UTC
Requires
- php: >=7.1.0
This package is auto-updated.
Last update: 2024-09-15 11:44:10 UTC
README
此模块可以帮助您为自定义模块内的图片生成缩略图和webp/avif替代品。
需求
使用此模块需要 PHP 7.1+。
安装
PrestaShop 8.0+
对于 PrestaShop 8.0+,使用以下命令通过 Composer 安装插件
composer require aeyoll/image_retriever
使用方法
假设您在模块中有一个图片文件,位于 modules/your_module/img/test.jpg
。
<?php use PrestaShop\Module\ImageRetriever\Service\ImageRetrieverService; $irs = new ImageRetrieverService(); $image = $irs->getImage( _PS_MODULE_DIR_ . 'your_module/img/', // The absolute path to the uploaded images folder 'test.jpg', // The image filename ['home_default'] // Optional: generate only specific image types, otherwise generate every format );
在您的模板中
<picture> {if !empty($image.bySize.home_default.sources.avif)} <source srcset="{$image.bySize.home_default.sources.avif}" type="image/avif"> {/if} {if !empty($image.bySize.home_default.sources.webp)} <source srcset="{$image.bySize.home_default.sources.webp}" type="image/webp"> {/if} <img class="img-fluid" src="{$image.bySize.home_default.url}" alt="" width="{$image.bySize.home_default.width}" height="{$image.bySize.home_default.height}"> </picture>