Skip to content

Unable to convert TIFF to JPEG file #9484

Closed

Description

@ankit396

Code :

import os
from PIL import Image

yourpath = os.getcwd()
for root, dirs, files in os.walk(yourpath, topdown=False):
    for name in files:
        #print(os.path.join(root, name))
        if os.path.splitext(os.path.join(root, name))[1].lower() == ".tif":
            if os.path.isfile(os.path.splitext(os.path.join(root, name))[0] + ".jpg"):
                print("A jpeg file already exists for %s",name)
            # If a jpeg is *NOT* present, create one from the tiff.
            else:
                outfile = os.path.splitext(os.path.join(root, name))[0] + ".jpg"
                try:
                    im = Image.open(os.path.join(root, name))
                    print("Generating jpeg for %s",name)
                    im.thumbnail(im.size)
                    im.save(outfile, "JPG", quality=100)
                except:
                  print("Something went wrong!")

Given this code above, it shows below error :

**ERROR:PIL.TiffImagePlugin:More samples per pixel than can be decoded: 13
Something went wrong!
ERROR:PIL.TiffImagePlugin:More samples per pixel than can be decoded: 13
Something went wrong!**

What did you do? : I wrote code that will convert tif file to jpg
What did you expect to happen? : The code will convert tif file to jpg
What actually happened? : It was unable to convert with the error pasted above.
What versions of Pillow and Python are you using? : pillow==11.3.0, Python 3.12.13

Activity

  1. radarhere commented on Mar 22, 2026

    @radarhere
    Member

    Are you able to upload a copy of the specific TIFF image that is causing the problem?

  2. ankit396 commented on Mar 23, 2026

    @ankit396
    Author

    The code checks for each tif file inside the current working directory. It outputted so for all the tif files

  3. radarhere commented on Mar 23, 2026

    @radarhere
    Member

    Our test suite does check for basic TIFF functionality, so I feel confident it is not a universal problem for TIFF images. I have to conclude that your images are unusual in some way.

    Without access to one of those TIFF files to inspect it and test that the result of our fix looks correct, it is hard to help. So far, all I know is that there are 13 samples per pixel in these images. I don't know whether the images have RGB, CMYK, LAB or grayscale data. I don't know if there's an alpha channel, or even a palette.

  4. ankit396 commented on Mar 25, 2026

    @ankit396
    Author
  5. ankit396 commented on Mar 25, 2026

    @ankit396
    Author

    I have attached one tif file

  6. radarhere commented on Mar 29, 2026

    @radarhere
    Member

    I've created #9514 to fix opening sentinel_1_625_inhabited_-140.09105608128587_-9.366613767927328.tif

    However, it is a F mode image, which means that even if change is made to Pillow so that the image can be opened, you would still need to convert it to another mode to save it as a JPEG.

    With the PR,

    from PIL import Image
    im = Image.open("sentinel_1_625_inhabited_-140.09105608128587_-9.366613767927328.tif")
    im.point(lambda v: v * 255).convert("L").save("result.jpg")

    gives

    pillow==11.3.0

    Is there any reason you're not using the latest Pillow version? I ask, because any fix for this would only be applied against a new version of Pillow.

    https://pillow.readthedocs.io/en/stable/releasenotes/index.html

    Please use the latest version of Pillow. Functionality and security fixes should not be expected to be backported to earlier versions.

  7. changed the title [-]Unable to convert tif to JPEG file[/-] [+]Unable to convert TIFF to JPEG file[/+] on Mar 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions