Using the "Generate XYZ Tiles" command from "Raster tools" it is possible to create a MBTiles format file containing either PNG or JPG images. I would like to create an MBTiles file containing WebP formatted images. The WebP raster driver is already installed, so is this not possible, a missing UI option, or is there something else I need to do to make this possible?

enter image description here enter image description here

3 Answers 3


The Generate XYZ Tiles (MBTiles) tool uses GDAL to generate the output.

The GDAL MBTiles driver documentation states it only supports PNG and JPG output, so may only support <= version 1.2 of the MBTiles spec. WebP support was added to the MBTiles spec at v. 1.3.

There is an open GDAL enhancement ticket (#3437) requesting WebP support be added.

So in short, doesn't look like you can enable WebP output with the QGIS Generate XYZ Tiles (MBTiles) tool.

However, maptiler engine supports MBTiles and WebP output and has a free desktop version. I haven't used it so can't comment on it other than that.


Under the hood MBTiles is SQLite so you can use SQLite and PIL to convert the images to webp. here is a sketch of how i have done it for tiles that start as png8. I am new to SQLite so feel free to tell me how to tighten it up.

import sqlite3 
import io
from PIL import Image

conn = sqlite3.connect(FullPathToFile)
cursor = conn.cursor()
cursor.execute('SELECT rowid,* FROM tiles')
data = cursor.fetchall()
for row in data:
    tile_data = row[tData] 
    im = Image.open(io.BytesIO(tile_data)) #https://pillow.readthedocs.io/en/stable/handbook/tutorial.html#reading-from-binary-data
    im.save(stream, format="WebP", lossless=True, quality=100, method=5) #https://pillow.readthedocs.io/en/stable/handbook/image-file-formats.html#webp
    imagebytes = stream.getvalue()
        sql_update_query = "UPDATE tiles SET tile_data=? WHERE rowid=?"
        cursor.execute(sql_update_query, (imagebytes,rID))
    except sqlite3.Error as error:
        print("Failed to update sqlite table", error)

You can first create tms tiles with gdal

gdal2tiles.py --zoom=18 --tiledriver=WEBP --webp-quality=50 inputFiles.vrt tiles

then use https://github.com/mapbox/mbutil and run

mb-util --image_format=webp --scheme=tms tiles yourOutputfile.mbtiles

Btw: if you want to work with multiple input files, start with the following command to build a virtual mosaic: gdalbuildvrt inputFiles.vrt input/*.jpg

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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