# create transparency band for f in *tif; do gdal_translate -b 1 -ot Byte $f red.tif; gdal_translate -b 2 -ot Byte $f green.tif; gdal_translate -b 3 -ot Byte $f blue.tif; gdal_translate -a_nodata none $f no.tif; gdal_calc.py -A no.tif --outfile=mask.tif --calc="(A<=255)*255"; gdal_merge.py -separate -o ../ToCompress/$f red.tif green.tif blue.tif mask.tif; sudo rm red.tif; sudo rm green.tif; sudo rm blue.tif; sudo rm no.tif; sudo rm mask.tif; done # compress using tiled jpeg for f in *.tif do gdal_translate -co COMPRESS=JPEG -co TILED=YES $f ../ToUpload/$f; done # create overviews for f in *.tif do gdaladdo --config COMPRESS_OVERVIEW JPEG --config INTERLEAVE_OVERVIEW PIXEL -r average $f 2 4 8 16 32 64; done