0

I have a set of raster png MBTiles that are way too big in terms of file size. I need to get them down to close to half. I was hoping to achieve it by converting them to JPG Mbtiles, as they are currently PNG.

Do you know any tools that can achieve that?

2

If your data is sourced from a single zoom level, e.g. aerial imagery

GDAL does this easily:

gdal_translate -co TILE_FORMAT=JPEG \
-of MBTILES png.mbtiles jpg.mbtiles

For generating the zoom levels, one needs to use gdaladdo afterwards:

gdaladdo -r average jpg.mbtiles

For more information on the tools, see https://www.gdal.org/gdal_translate.html and https://www.gdal.org/gdaladdo.html

For more information on the format and the options GDAL offers when writing it (for example QUALITY), see https://www.gdal.org/frmt_mbtiles.html

If you have different styles per zoom level

Using the GDAL approach above would drop all your zoom levels except the highest one and recalculate the others. This will be bad if you had per-zoomlevel styles. In that case you can use mbutil and any tool you like for mass-converting images from PNG to JPEG:

First extract all the tiles:

mb-util png.mbtiles tiles

Then convert all the PNG files to JPEG, I used this on Linux:

find tiles -name "*.png" | xargs convert -verbose -format jpg -quality 85

Then collect the tiles into a mbtiles file again:

mb-util --image_format=jpg tiles jpg2.mbtiles
  • 1
    Excellent. Above and beyond the call of duty, thanks! – paul_f Apr 26 at 13:01
1

If your tiles are aerial photos, png->jpg is a great solution for cutting down on size. However, the more the tiles have drawn features (lines, contours, area fills especially patterned ones, symbols, etc. that were rendered into raster format in your original mbtiles from vector layers somewhere), the more jpg compression may generate artifacts.

If that's the case, it's worth checking what compression has been applied to the embedded PNGs. In case they're 32-bit PNGs and/or not compressed, you could try repacking as PNG8 or with a high ZLEVEL (referring to the GDAL options linked to by bugmenot123's answer). This approach will however probably be worse if the tiles are aerials; it's a tradeoff.

Bottom line is I'd start by extracting out one sample detailed tile, and then use gdal_translate to explore converting it both to jpg (at different quality levels) and png/png8 with different zlevels, checking the impact on both tile size and quality before processing the whole mbtile file.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.