How to create transparent tif images using GDAL?

Use galdem to add color to your tif file.

gdaldem color-relief input.tif style.txt -alpha output.tif

style.txt looks like this, with each line has five values. First one is value of raster, next three are RGB value, fifth one is alpha

3500   white
2500   235:220:175
50%   190 185 135
700    240 250 150
0      50  180  50
nv     0   0   0   0

By default, it uses linear interpolation of color for other values. Use -exact_color_entry or -nearest_color_entry to avoid linear interpolation. Alpha (fifth value) is used for transparency, 255 means (by default) no transparency, 0 denotes fully transparent.


GDAL & TIFF:

Using GDAL utilities, but not gdalwarp specifically...

As per the answer at GDAL: Convert specific RGB (GeoTIFF) color to transparent , the following has worked for some users' GeoTIFFs.

Create a VRT for the image setting nodata for the pixel value that you want to be transparent:

gdalbuildvrt -srcnodata "255 255 255" virtualimage.vrt input.tiff

Then create a new TIFF using the VRT as input:

gdal_translate virtualimage.vrt output.tiff

You'd have to check that "255 255 255" was in fact the correct pixel value for you to use, and adjust it to something else, if necessary.

WMS:

You commented that you are viewing through a WMS service. Make sure that you are requesting PNGs from your WMS and not JPEGs. JPEG cannot include transparency and the service will fill in any transparent pixels as either white or black when converting to JPEG (depending on the implementation).

Tags:

Gdal

Gdalwarp