A fast, multi-threaded tool to slice large images into map‑style tiles at multiple zoom levels.
- Automatic zoom‑level calculation: Dynamically determines how deep to go based on image dimensions and a configurable magnification factor.
- Worker‑thread pool: Fully utilizes all CPU cores via
worker_threads
.
# npm
npm install tilegen -g
# yarn
yarn add tilegen -g
# pnpm
pnpm add tilegen -g
# bun
bun add tilegen -g
Before installing, make sure you have Bun installed on your system.
git clone https://github.com/itsbrunodev/tilegen.git
cd tilegen
bun install
To get help, run the following command:
tilegen -h
tilegen can be used from the command-line with the following options:
Option | Description | Default |
---|---|---|
-t, --tile-size <TILE_SIZE> |
The tile size of each image. | 256 |
-f, --tile-format <TILE_FORMAT> |
The format of the output tiles. | webp |
-m, --max-mag <MAXIMUM_MAGNIFICATION> |
The maximum magnification factor. | 1 |
-i, --input <INPUT_PATH> |
The path to the input image. | ./input.png |
-o, --output <OUTPUT_DIR> |
The path to the output directory where the tiles will be saved. | ./out/ |
tilegen -t 512 -f webp -m 4 -i ./input.png -o ./out/
This will generate tiles at ./out/{z}/{x}/{y}.webp
, with a tile size of 512
and a maximum magnification of 4
from the input image ./input.png
.
MAXIMUM_MAGNIFICATION
controls how deep your zoom levels go. It adjusts how many source‑pixels each tile covers at the deepest level.
Increasing it by 1 gives you one extra zoom‑in level (more detail at deepest zoom), at the cost of more tiles and storage.
For example, if MAXIMUM_MAGNIFICATION
is 4
, at the deepest zoom level, each tile will cover 4x4 = 16 source pixels. If the input image is 1024x1024, this means there will be 4 zoom levels in total (2^4 = 16
).
soon
I've made a post on dev.to which you can check out to see an in-depth explanation of how this tool works.
tilegen is under the MIT license.