承接 contenir/contenir-asset-laminas-mvc 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

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 + assetvariant route — 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 responsive srcset over the configured width ladder.
    • storageSources($path, $widths = null, $sizes = null)<source> elements (AVIF, WebP) for a <picture>, with lazy data-lazysrc-srcset attributes.
  • 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

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2026-06-10

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固