Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

exif_transpose(img) TypeError exception on file that GIF and Javascript are happy to process #7340

Closed
johngrabner opened this issue Aug 14, 2023 · 2 comments

Comments

@johngrabner
Copy link

johngrabner commented Aug 14, 2023

What did you do?

        try:
            img = ImageOps.exif_transpose(img)
        except TypeError:
            print(f"TypeError occurred!, file {img_path}")

What did you expect to happen?

rotate the file 90 degrees

What actually happened?

exception TypeError

error occurs here

def tobytes(self, offset=8):
   ...
   return b"Exif\x00\x00" + head + ifd.tobytes(offset) 

TiffImagePlugin.py:: tobytes(self, offset=0):
   ...
   for tag, value in sorted(self._tags_v2.items()): ..... 41th interation tag ==5, value=0
       ...
       logger.debug(f"Tag {tag}, Type: {typ}, Value: {repr(value)}")
       'Tag 5, Type: 1, Value: 0'
       ...
       values = value if isinstance(value, tuple) else (value,)  .... value==(0,)
       data = self._write_dispatch[typ](self, *values) .... data==0
       ... 
      msg = f"save: {tagname} ({tag}) - type: {typname} ({typ})"
      .... at this point msg == 'save: GPSAltitudeRef (5) - type: byte (1)'
      ... this statement crashes because len(data) TypeError: object of type 'int' has no len()
      msg += " - value: " + (
      "<table: %d bytes>" % len(data) if len(data) >= 16 else str(values)
      )

debug logging causes the crash.

What are your OS, Python and Pillow versions?

  • OS: Ubuntu 18.04.6 LTS (x86_64)

  • docker image FROM pytorch/pytorch:1.13.1-cuda11.6-cudnn8-runtime

  • Python: Python version: 3.10.8 (main, Nov 4 2022, 13:48:29) [GCC 11.2.0] (64-bit runtime)
    Python platform: Linux-5.15.0-78-generic-x86_64-with-glibc2.27

  • Pillow: '9.3.0'

Here is one of may files having this problem.

20220721_181853

@radarhere
Copy link
Member

Hi. Testing your image, this was fixed by #6740 in Pillow 9.4.0.

So the solution here is simply to upgrade your Pillow to a more recent version.

@johngrabner
Copy link
Author

Thank you

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants