close
The Wayback Machine - https://web.archive.org/web/20201107085928/https://github.com/BergWerkGIS/optimize-png-mbtiles
Skip to content
master
Go to file
Code

Latest commit

 

Git stats

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
 
 
 
 
 
 

README.md

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.

Image

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

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

On my laptop optimizing basemapat_standard16.MBTiles takes about:

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

Image

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
You can’t perform that action at this time.