Skip to content

Unable to convert TIFF to JPEG file #9484

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

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