I have the following code which batch saves rasters in qgis using the python terminal:


    myDir = 'd:/output/'
    layers = iface.legendInterface().layers()
    pipe = QgsRasterPipe()
    for layer in layers:
        extent = layer.extent()
        width, height = layer.width(), layer.height()
        renderer = layer.renderer()
        provider=layer.dataProvider()
        crs = layer.crs().toWkt() 
        pipe.set(provider.clone())
        pipe.set(renderer.clone())
        file_writer = QgsRasterFileWriter(myDir + layer.name() + ".tif")
        file_writer.writeRaster(pipe,
		     			        width,
                                height,
                                extent,
                                layer.crs())

The tifs that are saved are uncompressed, does anyone know how to turn on compression like LZW?

Thank you.