contenir/contenir-asset-laminas-mvc
最新稳定版本:v0.1.0
Composer 安装命令:
composer require contenir/contenir-asset-laminas-mvc
包简介
Laminas MVC adapter for Contenir assets — on-demand responsive image variants (incl. WebP/AVIF) backed by contenir/storage.
README 文档
README
Laminas MVC adapter for Contenir assets. Serves on-demand responsive image
variants — including WebP and AVIF — backed by
contenir/storage's ImageResizer.
This is the MVC flavour of the Contenir asset layer (the core + -laminas-mvc
convention). The generation engine lives in contenir/storage; HTTP serving and
the view helpers live here.
What it provides
AssetVariantController+assetvariantroute — serves/asset/<folder>/_variant/<dimensions>/<filename>. Existing variant files are served directly by the web server; only missing ones reach the controller, which resizes on demand and streams the result.- View helpers for templates:
storageUrl($path, $dimensions = null, $format = null)— a single URL (original, or a_variant/<dimensions>/variant).storageSrcSet($path, $widths = null, $format = null)— a responsivesrcsetover the configured width ladder.storageSources($path, $widths = null, $sizes = null)—<source>elements (AVIF, WebP) for a<picture>, with lazydata-lazysrc-srcsetattributes.
AssetUrlBuilder— the pure string URL builder behind the helpers. Returns raw URLs; escaping is the output context's job (htmlAttributes()escapes — escaping here too would double-encode).
URL scheme
/asset/<folder>/_variant/<dimensions>/<file>.<fmt>
<dimensions> is Wx (width-bound, e.g. 480x), xH (height-bound, e.g.
x900), or WxH (e.g. 480x900) — the same geometry vocabulary as ImageMagick.
<fmt> is the source extension, webp, or avif. The responsive srcset ladder
emits Wx tokens.
A WxH request crops to fill (Cover); a single-axis request fits inside
(Contain). When the requested format cannot be produced (e.g. the ImageMagick
build lacks AVIF), the controller falls back to a source-format variant so the URL
returns valid image bytes with the real Content-Type rather than a 404.
Installation
composer require contenir/contenir-asset-laminas-mvc
If you use laminas/laminas-component-installer, the module is registered
automatically; otherwise add Contenir\Asset\Laminas\Mvc to
config/modules.config.php.
Configuration
Override the defaults per-site in config/autoload/storage.global.php:
return [ 'storage' => [ 'asset' => [ 'root_path' => 'public', 'public_path' => '', 'variant_widths' => [320, 480, 600, 760, 960, 1280, 1440, 1920, 2560], 'variant_formats' => ['avif', 'webp'], // 'binary' => '/opt/homebrew/bin/magick', // optional; auto-discovered otherwise ], ], ];
Usage in templates
<picture>
<?= $this->storageSources($path, [480, 960, 1440]) ?>
<img
data-lazysrc
data-lazysrc-srcset="<?= $this->storageSrcSet($path, [480, 960, 1440]) ?>"
src="<?= $this->storageUrl($path, '480x') ?>"
alt="">
</picture>
统计信息
- 总下载量: 0
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 2
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2026-06-10