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

Can't open a tiff with old-style jpeg compressed file #7414

Closed
xiaoyzhou opened this issue Sep 21, 2023 · 5 comments · Fixed by #7415
Closed

Can't open a tiff with old-style jpeg compressed file #7414

xiaoyzhou opened this issue Sep 21, 2023 · 5 comments · Fixed by #7415
Labels

Comments

@xiaoyzhou
Copy link

xiaoyzhou commented Sep 21, 2023

What did you do?

I can get the infomation from tiffinfo.

$ tiffinfo 20230822143148.tif 
TIFF Directory at offset 0x8 (8)
  Subfile Type: multi-page document (2 = 0x2)
  Image Width: 2340 Image Length: 1654
  Resolution: 200, 200 pixels/inch
  Bits/Sample: 8
  Compression Scheme: Old-style JPEG
  Photometric Interpretation: min-is-black
  FillOrder: msb-to-lsb
  YCbCr Subsampling: 2, 2
  YCbCr Positioning: centered
  Orientation: row 0 top, col 0 lhs
  Samples/Pixel: 1
  Rows/Strip: 1654
  Planar Configuration: single image plane
  Page Number: 0-0
  Software: Apeos C7070
  JpegInterchangeFormat: 306
  JpegInterchangeFormatLength: 405550
  JpegProc: 1
  JpegRestartInterval: 0

But when i use python, get the under error.
PIL.UnidentifiedImageError: cannot identify image file '20230822143148.tif'

What did you expect to happen?

Pillow will open the file without error.

What actually happened?

I get the under error.
PIL.UnidentifiedImageError: cannot identify image file '20230822143148.tif'

What are your OS, Python and Pillow versions?

  • OS: Windows 10 (22H2)
  • Python: 3.9.13
  • Pillow: 9.5.0
code goes here
@radarhere
Copy link
Member

Can you attach a copy of the image itself?

@xiaoyzhou
Copy link
Author

20230822143148.zip
@radarhere

I upload it.

@xiaoyzhou
Copy link
Author

xiaoyzhou commented Sep 21, 2023

Test code.

import sys
from PIL import Image, TiffImagePlugin, features

filename = sys.argv[1]

TiffImagePlugin.DEBUG = True
TiffImagePlugin.READ_LIBTIFF = True

with Image.open(filename, mode='r', formats=['TIFF']) as img:
  img.load()
  TiffImagePlugin.READ_LIBTIFF = False
  print(img.width, img.height)
  print(img.info)

print(features.version_codec("libtiff"))

@radarhere
Copy link
Member

I've created PR #7415 to resolve this.

In the meantime, here's a version of your code with a line added to make it work.

import sys
from PIL import Image, TiffImagePlugin, features

filename = sys.argv[1]

TiffImagePlugin.DEBUG = True
TiffImagePlugin.READ_LIBTIFF = True

# New line
TiffImagePlugin.OPEN_INFO[(b"II", 6, (1,), 1, (8,), ())] = ("L", "L")

with Image.open(filename, mode='r', formats=['TIFF']) as img:
  img.load()
  TiffImagePlugin.READ_LIBTIFF = False
  print(img.width, img.height)
  print(img.info)

print(features.version_codec("libtiff"))

@xiaoyzhou
Copy link
Author

Thanks a lot。

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

Successfully merging a pull request may close this issue.

2 participants