I have been using the Pillow code below to convert Tiff to Jpeg, but have recently found that I can use Gdal to also convert Tiff to Jpeg. I am trying to understand what the main difference is between them and if there is a reason why I should be using one over the other? Is there a quality difference? I would prefer to use the gdal code to limit the amount of packages I need in my overarching script.

The purpose is to use the JPEG's within computer vision - tensorflow - pytorch - YOLO - etc.



for infile in os.listdir(tif_path):
    if infile[-3:] == "tif" or infile[-3:] == "bmp":
        outfile = infile[:-3] + "jpeg"
        im = Image.open(tif_path + '/' + infile)
        out = im.convert("RGB")
        out.save(jpeg_dst + outfile, "JPEG", quality=90)


options_list = [
    '-ot Byte',
    '-of JPEG',
    '-b 1',

options_string = " ".join(options_list)

1 Answer 1


Pillow seems to use the IJG JPEG library https://jpegclub.org/reference/about-ijg/. GDAL may use the same or libtiff-turbo https://gdal.org/drivers/raster/jpeg.html

The GDAL JPEG Driver is built using the Independent JPEG Group’s jpeg library. Also note that the GeoTIFF driver supports tiled TIFF with JPEG compressed tiles. This can be used to apply JPEG compression to datasets that exceed the maximum dimensions of 65,535x65,535 pixels for a single JPEG image.

It is also possible to use the JPEG driver with the libjpeg-turbo, a version of libjpeg, API and ABI compatible with IJG libjpeg-6b, which uses MMX, SSE, and SSE2 SIMD instructions to accelerate baseline JPEG compression/decompression.

Starting with GDAL 3.4, read and write support for JPEG images with 12-bit sample is enabled by default (if JPEG support is also enabled), using GDAL internal libjpeg (based on IJG libjpeg-6b, with additional changes for 12-bit sample support). Support for JPEG with 12-bit sample is independent of whether 8-bit JPEG support is enabled through internal IJG libjpeg-6b or external libjpeg (like libjpeg-turbo)

If you want to be sure that the results are similar use a GDAL version that is build with the IJG JPEG library but the two other options should be compatible as well when it comes to features which are supported by IJG libjpeg-6b.

  • Appreciate the links and information.
    – Binx
    Jun 27, 2022 at 22:10

Your Answer

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

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