Skip to content

Latest commit

 

History

History
63 lines (43 loc) · 3.18 KB

README.md

File metadata and controls

63 lines (43 loc) · 3.18 KB

optimize-png-mbtiles

Walks through all tiles in an mbtiles file (only raster PNG mbtiles supported) and optimizes them (in place!) using pngquant.

optimize-png-mbtiles has been developed for and tested with basemap.at Verwaltungskarte Raster Offline Österreich (bmap_standard_mbtiles_L00bisL16.zip).

If it works with other mbtiles files is a game of luck and depends on their internal database schema and how they were created. While basemapat_standard16.MBTiles adheres to the mbtiles spec from a read-only point of view, its internal database schema is different from the schema of mbtiles created with tools from the Mapbox universe (eg node-mbtiles).

No analysis of the actual database schema is performed and optimize-png-mbtiles most likely will not work with mbtiles created with Mapbox tools.

basemapat_standard16.MBTiles weighs in at +16GB which essentially makes it useless for its intended offline use (think mobile apps or shared hosting).

Maximum compression reduces those +16GB to ~4.6GB, still a lot, but much better to handle.

Maximum compression is of course noticeable in a side by side comparision, but not that bad either:

original optimized
127KB
31KB
131KB
31KB
128KB
33KB
137KB
32KB

On my laptop optimizing basemapat_standard16.MBTiles takes about:

  • ~30 minutes for tile optimization
  • ~3 minutes for final database vacuum

Usage

Note:

Make sure there's enough free RAM before starting the tool. 
At least 5GB (7GB recommended, the more the better).
The final database vacuum needs a lot of it.

Default settings are optimized for size, sacrificing some quality on the way.

Adjust settings to get desired output quality. Even moderate compression without visible degradation will save a few GBs already.

λ optimizepngmbtiles.exe
  -f, --mbtiles=VALUE        Path to MBTiles
  -m, --min-quality=VALUE    PNG min quality [0..100]. Default:0
  -x, --max-quality=VALUE    PNG max quality [0..100]. Default:20
  -s, --speed=VALUE          PNG speed [1..10]. Slower better quality. Default:1
  -t, --threads=VALUE        Threads. Default (Processors):8
  -b, --batch-size=VALUE     Batch size. Number of tiles processed in one batch.
                                Default:1000