Friday, December 12, 2008

Python, GDAL: Set JPEG quality values and other att

Here I shall show how to set the quality values of the JPEG format in GDAL. This post will build upon this previous article which describes how to create a basic JPEG.

It is pretty trivial to set the quality (and other) JPEG values. Here is a list of parameters one can set for the JPEG format. These parameters are simply passed to the CreateCopy() method as a list of options. Here's an example:
# ... Some other code ... #

if (cmp(output_file_ext.lower(),".jpg") == 0 or cmp(output_file_ext.lower(),".jpeg") == 0):
# Add options
options = []

jpg_driver = gdal.GetDriverByName("JPEG")

# Pass options as parameter
jpg_driver.CreateCopy( output_file, dst_ds, options=options )


Anthony Awtrey said...

Thanks! This was just what I needed.

samoo7 said...

Hi can u tell me how can i convert other raster formats (like BIL) to GeoTIFF??