PHPackages                             simonvomeyser/commonmark-ext-lazy-image - 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. simonvomeyser/commonmark-ext-lazy-image

ActiveCommonmark-extension[Image &amp; Media](/categories/media)

simonvomeyser/commonmark-ext-lazy-image
=======================================

Adds support for lazy images to the phpleague/commonmark markdown parser package

v2.0.3(3y ago)1821.3k↑21.1%31MITPHPPHP ^7.4 || ^8.0CI failing

Since Jul 21Pushed 3y agoCompare

[ Source](https://github.com/simonvomeyser/commonmark-ext-lazy-image)[ Packagist](https://packagist.org/packages/simonvomeyser/commonmark-ext-lazy-image)[ RSS](/packages/simonvomeyser-commonmark-ext-lazy-image/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (5)Dependencies (2)Versions (9)Used By (1)

Extension to render lazy images in markdown
===========================================

[](#extension-to-render-lazy-images-in-markdown)

[![Tests](https://github.com/simonvomeyser/commonmark-ext-lazy-image/workflows/Tests/badge.svg)](https://github.com/simonvomeyser/commonmark-ext-lazy-image/workflows/Tests/badge.svg)

This adds support for lazy images to the [league/commonmark](https://github.com/thephpleague/commonmark) package version `^2.0`.

Install
-------

[](#install)

```
composer require simonvomeyser/commonmark-ext-lazy-image
```

⚠️ When you are using Version 1.0 of league\\commonmark

The current version of this pacakge is only compatible with `League\\CommonMark 2.0`, for `1.0` compatibility install the latest `1.0` version of this package like so: ```
composer require simonvomeyser/commonmark-ext-lazy-image "^v1.2.0"
```

You can find the old documentation [here](https://github.com/simonvomeyser/commonmark-ext-lazy-image/tree/40fcb3ec18b1c84e21a0b0b635ad021f8ec933bd).

Example
-------

[](#example)

```
use League\CommonMark\Environment\Environment;
use League\CommonMark\Extension\CommonMark\CommonMarkCoreExtension;
use SimonVomEyser\CommonMarkExtension\LazyImageExtension;

$environment = new Environment([]);
$environment->addExtension(new CommonMarkCoreExtension())
            ->addExtension(new LazyImageExtension());

$converter = new MarkdownConverter($environment);
$html = $converter->convert('![alt text](/path/to/image.jpg)');
```

This creates the following HTML

```

```

Options/Configuration
---------------------

[](#optionsconfiguration)

By default, only the `loading="lazy"` attribute is added

While this should hopefully be sufficient [in the future](https://web.dev/native-lazy-loading/), you can use the provided options to integrate with various lazy loading libraries.

Here is an example how to use this package with the [lozad library](https://github.com/ApoorvSaxena/lozad.js):

```
$environment = new Environment([
    // ... other config
    'lazy_image' => [
        'strip_src' => true, // remove the "src" to add it later via js, optional
        'html_class' => 'lozad', // the class that should be added, optional
        'data_attribute' => 'src', // how the data attribute is named that provides the source to get picked up by js, optional
    ]
]);
$environment->addExtension(new CommonMarkCoreExtension())
    ->addExtension(new LazyImageExtension());

$converter = new MarkdownConverter($environment);

$html = $converter->convert('![alt text](/path/to/image.jpg)');
```

This creates the following HTML

```

```

###  Health Score

38

—

LowBetter than 85% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity37

Limited adoption so far

Community14

Small or concentrated contributor base

Maturity65

Established project with proven stability

 Bus Factor1

Top contributor holds 82.9% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~131 days

Recently: every ~144 days

Total

7

Last Release

1341d ago

Major Versions

v1.2.0 → v2.0.02021-09-13

PHP version history (3 changes)v1.0.0PHP ^7.1

v1.2.0PHP ^7.1 || ^8.0

v2.0.0PHP ^7.4 || ^8.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/b477d90256d212d4edc53d2de4cd142c3c58a00938518edd9ef6fc6cc27dfddb?d=identicon)[simonvomeyser](/maintainers/simonvomeyser)

---

Top Contributors

[![simonvomeyser](https://avatars.githubusercontent.com/u/10830728?v=4)](https://github.com/simonvomeyser "simonvomeyser (29 commits)")[![ElGigi](https://avatars.githubusercontent.com/u/18268216?v=4)](https://github.com/ElGigi "ElGigi (3 commits)")[![usernotnull](https://avatars.githubusercontent.com/u/15612814?v=4)](https://github.com/usernotnull "usernotnull (3 commits)")

---

Tags

imagemarkdowncommonmarkextensionlazy

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/simonvomeyser-commonmark-ext-lazy-image/health.svg)

```
[![Health](https://phpackages.com/badges/simonvomeyser-commonmark-ext-lazy-image/health.svg)](https://phpackages.com/packages/simonvomeyser-commonmark-ext-lazy-image)
```

###  Alternatives

[maxmirazh33/yii2-uploadable-cropable-image

Yii2 extension for upload and crop images

1020.8k](/packages/maxmirazh33-yii2-uploadable-cropable-image)[somehow-digital/typo3-media-processing

Media Processing

101.1k](/packages/somehow-digital-typo3-media-processing)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
