PHPackages                             contenir/contenir-asset-laminas-mvc - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Image &amp; Media](/categories/media)
4. /
5. contenir/contenir-asset-laminas-mvc

ActiveLibrary[Image &amp; Media](/categories/media)

contenir/contenir-asset-laminas-mvc
===================================

Laminas MVC adapter for Contenir assets — keyed, profile-driven responsive image variants (incl. WebP/AVIF) backed by contenir/storage.

v0.5.0(2w ago)040↓80%MITPHPPHP ^8.1 || ^8.2 || ^8.3

Since Jun 10Pushed 2w agoCompare

[ Source](https://github.com/contenir/contenir-asset-laminas-mvc)[ Packagist](https://packagist.org/packages/contenir/contenir-asset-laminas-mvc)[ RSS](/packages/contenir-contenir-asset-laminas-mvc/feed)WikiDiscussions main Synced 1w ago

READMEChangelog (1)Dependencies (18)Versions (12)Used By (0)

contenir/contenir-asset-laminas-mvc
===================================

[](#contenircontenir-asset-laminas-mvc)

Laminas MVC adapter for Contenir assets. Serves **on-demand responsive image variants** — including **WebP** and **AVIF** — backed by [`contenir/storage`](https://github.com/contenir/storage)'s `ImageResizer`.

Variants are **keyed by profile**: a template passes one profile key (e.g. `'tile'`) and the responsive behaviour — widths, crop/scale, quality, the HTML `sizes` attribute, and output formats — all comes from the shared `settings.storage.profiles` config that the CMS reads too. No per-template width lists, no hand-written `sizes`. Generated variant files share the `_variant//` directory `contenir/storage` writes to, so the CMS-generated renditions and the front-end's format siblings live together.

What it provides
----------------

[](#what-it-provides)

- **`AssetVariantController` + `assetvariant` route** — serves `/asset//_variant//`. Existing variant files are served directly by the web server; only missing ones reach the controller, which resizes on demand (per the named variant's definition) and streams the result.
- **`ProfileProviderService`** — reads `settings.storage.profiles` and exposes typed `Contenir\Asset\Laminas\Mvc\Profile\Profile` / `Contenir\Storage\Variant`objects. Variant names are globally unique, so a bare name resolves to one definition.
- **View helpers** for templates:
    - `storageSrcSet($path, $profile)` — responsive `srcset` over the profile's variant ladder (source format).
    - `storageSizes($profile)` — the profile's configured `sizes` attribute.
    - `storageSources($path, $profile)` — `` elements (one per profile `formats` entry, e.g. AVIF then WebP) for a ``.
    - `storageUrl($path, $variant = null, $format = null)` — a single URL (original, or a named `_variant//` variant, optionally in a given format).
- **`AssetUrlBuilder`** — the pure string URL builder behind the helpers. Returns **raw** URLs; escaping is the output context's job.

URL scheme
----------

[](#url-scheme)

```
/asset//_variant//.

```

`` is a profile's variant key (e.g. `tile-640`); `` is the source extension, `webp`, or `avif`. 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 rather than a 404.

Installation
------------

[](#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
-------------

[](#configuration)

This package reads **two** config keys:

1. **`settings.storage.profiles`** — the shared profile catalogue (also read by the CMS). Each variant carries its own width/height/fit/quality; add a `sizes`string and a `formats` list per profile for the front-end:

    ```
    'settings' => [
        'storage' => [
            'profiles' => [
                'tile' => [
                    'type'       => 'local',
                    'rootPath'   => './public/asset/library',
                    'publicPath' => '/asset/library',
                    'sizes'      => '(min-width: 768px) 33vw, 100vw',
                    'formats'    => ['avif', 'webp'],
                    'variants'   => [
                        'admin-thumb' => ['width' => 180, 'height' => 180, 'fit' => 'contain'],
                        'tile-320'    => ['width' => 320, 'height' => 240, 'fit' => 'cover', 'quality' => 80],
                        'tile-640'    => ['width' => 640, 'height' => 480, 'fit' => 'cover', 'quality' => 80],
                    ],
                ],
            ],
        ],
    ],
    ```

    Variant names are **globally unique** across profiles (so `_variant//`is unambiguous and shared with `contenir/storage`). The `admin-thumb` variant is the CMS preview and is never emitted in front-end `srcset`/`sources`.
2. **`storage.asset`** — the on-disk / URL base, in `config/autoload/storage.global.php`:

    ```
    return [
        'storage' => [
            'asset' => [
                'root_path'   => 'public',
                'public_path' => '',
                // 'binary'   => '/opt/homebrew/bin/magick', // optional; auto-discovered otherwise
            ],
        ],
    ];
    ```

Usage in templates
------------------

[](#usage-in-templates)

One key drives everything:

```
