PHPackages                             arakne/php-map-parser - 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. arakne/php-map-parser

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

arakne/php-map-parser
=====================

Parser and renderer for Dofus maps, in PHP

v0.1.2(5mo ago)51272LGPL-3.0-or-laterPHPPHP ~8.4CI passing

Since Sep 29Pushed 5mo ago1 watchersCompare

[ Source](https://github.com/Arakne/php-map-parser)[ Packagist](https://packagist.org/packages/arakne/php-map-parser)[ RSS](/packages/arakne-php-map-parser/feed)WikiDiscussions master Synced 3w ago

READMEChangelogDependencies (4)Versions (4)Used By (0)

Dofus map parser in PHP
=======================

[](#dofus-map-parser-in-php)

[![Build](https://github.com/Arakne/php-map-parser/actions/workflows/build.yml/badge.svg)](https://github.com/Arakne/php-map-parser/actions/workflows/build.yml)[![Packagist](https://camo.githubusercontent.com/df042cbacb758cbab84e1ae0828145225c5ab669d507985dcafbf11c2d81481d/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6172616b6e652f7068702d6d61702d706172736572)](https://packagist.org/packages/arakne/php-map-parser)[![codecov](https://camo.githubusercontent.com/2d45d9ba0e3bfc46eb068bf6cd830a8e4355b00c27afa54400f1675b08fee4e2/68747470733a2f2f636f6465636f762e696f2f6769746875622f4172616b6e652f7068702d6d61702d7061727365722f67726170682f62616467652e7376673f746f6b656e3d7672656c536466576b70)](https://codecov.io/github/Arakne/php-map-parser)[![License](https://camo.githubusercontent.com/cf81a6ea06f4d089a13f472fef8d8c00c6c788f4a718c8738835aabbdb3ac2e9/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f4172616b6e652f7068702d6d61702d706172736572)](./COPYING.LESSER)

Parse Dofus retro maps from SWF files and render them as images, map tiles, or simply provide the map data in a structured format.

Installation and requirements
-----------------------------

[](#installation-and-requirements)

This library relies on [Arakne-Swf](https://github.com/Arakne/ArakneSwf), so it has the same requirements:

- PHP 8.4 or higher
- The `gd` and `Imagick` extension for image rendering
- The `zlib` extension for compressed SWF files
- `rsvg` or `Inkscape` installed (or embedded in Imagick) for SVG rendering
- `composer` to install the library

Tip

To improve performance, it's recommended to enable JIT on both CLI and FPM SAPIs.

The library uses Dofus client's files, so you need to download them first and make them available to your application.

After that, you can install the library using composer:

```
composer require arakne/php-map-parser
```

Usage
-----

[](#usage)

### With the facade class

[](#with-the-facade-class)

The class [`DofusMapParser`](src/DofusMapParser.php) provides a simple interface to parse and render maps, which is suitable for most use cases.

#### Create the facade

[](#create-the-facade)

```
use Arakne\MapParser\DofusMapParser;
use Arakne\MapParser\Loader\MapCoordinates;
use Arakne\MapParser\Tile\Cache\SqliteTileCache;
use Arakne\MapParser\Sprite\Cache\SqliteSpriteCache;
use Arakne\MapParser\Loader\MapKey;

// Configure paths
const DOFUS_CLIENT_PATH = '/path/to/dofus/client';

// Maps path is not required: if not set, maps will be loaded from the client path
const SERVER_MAP_PATH = '/srv/www/htdocs/dofus/maps';

const CACHE_DIR = __DIR__ . '/var/cache'

// Database can be used to get maps from coordinates and also get map keys
const DB_DSN = 'mysql:host=localhost;dbname=dofus';
const DB_USER = 'dofus';
const DB_PASSWORD = 'dofus';

// Instantiate the facade
$parser = new DofusMapParser(
    dofusPath: DOFUS_CLIENT_PATH,
    mapsPath: SERVER_MAP_PATH,

    // Configure map resolver from coordinates: this is used only if you want to use world map using leaflet for example
    mapByCoordinates: function (MapCoordinates $coordinates, int $superAreaId) {
        $pdo = new PDO(DB_DSN, DB_USER, DB_PASSWORD);

        // SQL query to get the map ID from coordinates and super area
        // In this example, Araknemu database structure is used
        $query = x, PDO::PARAM_INT);
        $stmt->bindValue(2, $coordinates->y, PDO::PARAM_INT);
        $stmt->bindValue(3, $superAreaId, PDO::PARAM_INT);
        $stmt->execute();

        $map = $stmt->fetch();

        if (!$map) {
            return null;
        }

        return (int) $map['id'];
    },

    // Configure cache. Rendering tiles is expensive, so caching them is recommended
    // SQLite provides good performances without flooding the filesystem with thousands of files
    tileCache: new SqliteTileCache(CACHE_DIR . '/tiles.db'),
    spriteCache: new SqliteSpriteCache(CACHE_DIR . '/sprites.db'),

    // Attachments will load extra data from the database (or any other sources)
    // This is required to load map key and coordinates
    attachmentsProviders: [
        function (MapStructure $map) {
            // Load map properties from the database
            // This example uses Araknemu database structure
            $query = 'SELECT * FROM maps WHERE id = ?';
            $pdo = new PDO(DB_DSN, DB_USER, DB_PASSWORD);

            $stmt = $pdo->prepare($query);
            $stmt->bindValue(1, $map->id, PDO::PARAM_INT);
            $stmt->execute();

            $map = $stmt->fetch();

            if (!$map) {
                return [];
            }

            // Any other attachments can be returned here as well
            // There will be accessible using $map->get(AttachmentClass::class)
            // So you can attach for example a list of NPCs, monsters, resources, etc.
            return [new MapKey($map['key']), new MapCoordinates($map['MAP_X'], $map['MAP_Y'], $map['SUBAREA_ID'])];
        },
    ],
);
```

#### Parse a map and iterate its cells

[](#parse-a-map-and-iterate-its-cells)

```
/** @var \Arakne\MapParser\DofusMapParser $parser */
// Load and parse the map with ID 37
$map = $parser->parse(37);

// Now you can access to all cells properties
foreach ($map->cells as $id => $cell) {
    echo "Cell {$id}\n";
    echo "  Ground: {$cell->ground->number}\n";
    echo "  Layer1: {$cell->layer1->number}\n";
    echo "  Layer2: {$cell->layer2->number}\n";
}
```

#### Render the map as an image

[](#render-the-map-as-an-image)

```
/** @var \Arakne\MapParser\DofusMapParser $parser */
// Directly render the map as an image
$img = $parser->render(37);

// Render returns a GD image object, so you must use GD functions to manipulate or save it
imagepng($img, 'map37.png');
```

#### Render worldmap with leaflet

[](#render-worldmap-with-leaflet)

Create a simple template with leaflet to display the world map and load tiles on demand.

```
DOCTYPE html>

    Dofus Map

,
    }).addTo(mymap);

```

Now you can create a simple tile server to serve map tiles on demand:

```
/** @var \Arakne\MapParser\DofusMapParser $parser */

// Get the tile renderer, here for amakna world map
$tiles = $parser->amaknaWorldMap();

// Warmup the cache using a CLI command
// php index.php warmup
// This will take some time (more than 1 hour) but will speed up tile rendering
// The tile renderer can be used without warmup and even in parallel of the warmup process
if (($argv[1] ?? null) === 'warmup') {
    $amaknaRenderer->warmup(
        function (string $name, int $current, int $total) {
            echo sprintf("Building %s (%d/%d)\n", $name, $current, $total);
        },
    );
    exit(0);
}

$page = trim($_SERVER['PATH_INFO'] ?? '', '/');

switch ($page) {
    case '':
        // Show the template with leaflet
        require __DIR__ . '/template.php';
        break;

    case 'tiles':
        // Get tile coordinates from the query string
        // Note: no validation is done here, so be sure to validate the input in a real application
        $x = (int) ($_GET['x'] ?? 0);
        $y = (int) ($_GET['y'] ?? 0);
        $z = (int) ($_GET['z'] ?? 0);

        // Render the tile
        $tile = $tiles->render($x, $y, $z);

        // Send the image to the browser
        header('Content-Type: image/png');
        imagepng($tile);
        break;

    default:
        http_response_code(404);
        echo "Not found";
        break;
}
```

License
-------

[](#license)

This library is shared under the [LGPLv3](./COPYING.LESSER) license.

###  Health Score

38

—

LowBetter than 83% of packages

Maintenance69

Regular maintenance activity

Popularity18

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity45

Maturing project, gaining track record

 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 ~44 days

Total

3

Last Release

178d ago

### Community

Maintainers

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

---

Top Contributors

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

---

Tags

dofus-retroleafletswf

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Type Coverage Yes

### Embed Badge

![Health badge](/badges/arakne-php-map-parser/health.svg)

```
[![Health](https://phpackages.com/badges/arakne-php-map-parser/health.svg)](https://phpackages.com/packages/arakne-php-map-parser)
```

###  Alternatives

[morrislaptop/laravel-popo-caster

Automatically cast JSON columns to rich PHP objects in Laravel using Symfony's Serializer

27646.3k](/packages/morrislaptop-laravel-popo-caster)

PHPackages © 2026

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