PHPackages                             phlak/commonmark-rewrite-local-image-urls - 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. [Utility &amp; Helpers](/categories/utility)
4. /
5. phlak/commonmark-rewrite-local-image-urls

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

phlak/commonmark-rewrite-local-image-urls
=========================================

CommonMark extension for rewriting local, relatiave image URLs to absolute URLs

1.0.0(2w ago)0961MITPHPCI passing

Since Jul 10Pushed 2w agoCompare

[ Source](https://github.com/PHLAK/commonmark-rewrite-local-image-urls)[ Packagist](https://packagist.org/packages/phlak/commonmark-rewrite-local-image-urls)[ Fund](https://paypal.me/ChrisKankiewicz)[ GitHub Sponsors](https://github.com/PHLAK)[ RSS](/packages/phlak-commonmark-rewrite-local-image-urls/feed)WikiDiscussions master Synced 1w ago

READMEChangelogDependencies (10)Versions (4)Used By (1)

CommonMark Rewrite Local Image URLs Extension
=============================================

[](#commonmark-rewrite-local-image-urls-extension)

 [![Become a Sponsor](https://camo.githubusercontent.com/00da07edf5fbff7528a4743d85563603f9284f02680e0ab1e73652e680878548/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4265636f6d655f612d53706f6e736f722d6363343139352e7376673f7374796c653d666f722d7468652d6261646765)](https://github.com/users/PHLAK/sponsorship) [![One-time Donation](https://camo.githubusercontent.com/e9b5aa71ffdb17943c10c6d6b4a3132b66a938495331e488ecbdad1f3c078879/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4d616b655f612d446f6e6174696f6e2d3030366262362e7376673f7374796c653d666f722d7468652d6261646765)](https://paypal.me/ChrisKankiewicz)
 [![Latest Stable Version](https://camo.githubusercontent.com/d2a3b0dff817d17508b117c6a55ece2ef7c4a4620cf9f186658b118903b3d05d/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f70686c616b2f636f6d6d6f6e6d61726b2d726577726974652d6c6f63616c2d696d6167652d75726c732e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/phlak/commonmark-rewrite-local-image-urls) [![Total Downloads](https://camo.githubusercontent.com/a8704442d98c4a17299c66c173302a79386b0fe95171e7347dfd347d92403fab/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f70686c616b2f636f6d6d6f6e6d61726b2d726577726974652d6c6f63616c2d696d6167652d75726c732e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/phlak/commonmark-rewrite-local-image-urls) [![License](https://camo.githubusercontent.com/3443d5c8a9987673287ddbb222191cdb450f652f79566266a15d219deaaa11af/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f50484c414b2f636f6d6d6f6e6d61726b2d726577726974652d6c6f63616c2d696d6167652d75726c733f7374796c653d666c61742d737175617265)](https://github.com/PHLAK/commonmark-rewrite-local-image-urls/blob/master/LICENSE) [![Tests Status](https://camo.githubusercontent.com/d6267d38457b7c1b9ab91df33de079993108410fd0b5a875dc2c8372f0c621e3/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f50484c414b2f636f6d6d6f6e6d61726b2d726577726974652d6c6f63616c2d696d6167652d75726c732f63692d73756974652e79616d6c3f7374796c653d666c61742d737175617265266c6162656c3d7465737473)](https://github.com/PHLAK/commonmark-rewrite-local-image-urls/actions)

---

CommonMark extension for rewriting local, relative image URLs to absolute URLs.

Requirements
------------

[](#requirements)

- [PHP](https://www.php.net)
    - [league/commonmark](https://commonmark.thephpleague.com)

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

[](#installation)

Install the extension with Composer.

```
composer require phlak/commonmark-rewrite-local-image-urls

```

Then add the extension to your CommonMark environment.

```
use League\CommonMark\Environment\Environment;
use League\CommonMark\Extension\CommonMark\CommonMarkCoreExtension;
use League\CommonMark\MarkdownConverter;
use PHLAK\CommonMarkExtensions\RewriteLocalImageURLs;

$environment = new Environment;
$environment->addExtension(new CommonMarkCoreExtension);
$environment->addExtension(new RewriteLocalImageURLs('https://example.com'));

$converter = new MarkdownConverter($environment);
```

Usage
-----

[](#usage)

When converting Markdown, any local, relative image URL will be rewritten to an absolute URL using the configured base URL.

```
$converter->convert('![alt text](image.png)');
// Returns:

$converter->convert('![alt text](/image.png)');
// Returns:

$converter->convert('![alt text](assets/images/photo.jpg)');
// Returns:
```

External image URLs are left unchanged.

```
$converter->convert('![alt text](https://external.com/image.png)');
// Returns:

$converter->convert('![alt text](//external.com/image.png)');
// Returns:
```

Changelog
---------

[](#changelog)

A list of changes can be found on the [GitHub Releases](https://github.com/PHLAK/commonmark-rewrite-local-image-urls/releases) page.

Troubleshooting
---------------

[](#troubleshooting)

For general help and support join our [GitHub Discussion](https://github.com/PHLAK/commonmark-rewrite-local-image-urls/discussions) or reach out on [Bluesky](https://bsky.app/profile/phlak.dev).

Please report bugs to the [GitHub Issue Tracker](https://github.com/PHLAK/commonmark-rewrite-local-image-urls/issues).

Copyright
---------

[](#copyright)

This project is licensed under the [MIT License](https://github.com/PHLAK/commonmark-rewrite-local-image-urls/blob/master/LICENSE).

###  Health Score

40

—

FairBetter than 86% of packages

Maintenance96

Actively maintained with recent releases

Popularity13

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity36

Early-stage or recently created project

 Bus Factor1

Top contributor holds 100% 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 ~15 days

Total

3

Last Release

18d ago

Major Versions

0.1.1 → 1.0.02026-08-09

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/53531?v=4)[Chris Kankiewicz](/maintainers/PHLAK)[@PHLAK](https://github.com/PHLAK)

---

Top Contributors

[![PHLAK](https://avatars.githubusercontent.com/u/53531?v=4)](https://github.com/PHLAK "PHLAK (4 commits)")

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Type Coverage Yes

### Embed Badge

![Health badge](/badges/phlak-commonmark-rewrite-local-image-urls/health.svg)

```
[![Health](https://phpackages.com/badges/phlak-commonmark-rewrite-local-image-urls/health.svg)](https://phpackages.com/packages/phlak-commonmark-rewrite-local-image-urls)
```

###  Alternatives

[laravel/framework

The Laravel Framework.

34.9k556.2M21.6k](/packages/laravel-framework)[helsingborg-stad/municipio

A bootstrap theme for creating municipality sites.

4028.6k10](/packages/helsingborg-stad-municipio)[grumpydictator/firefly-iii

Firefly III: a personal finances manager.

24.3k69.5k](/packages/grumpydictator-firefly-iii)[statamic/cms

The Statamic CMS Core Package

4.9k3.8M1.2k](/packages/statamic-cms)[tempest/framework

The PHP framework that gets out of your way.

2.3k37.6k21](/packages/tempest-framework)[roundcube/roundcubemail

The Roundcube Webmail suite

7.1k3.2k3](/packages/roundcube-roundcubemail)

PHPackages © 2026

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