Skip to content

Cannot save .TIF file with tag 297 (Page Number) having value of 0/0. #973

@jamesrusso

Description

@jamesrusso

Script:

from PIL import Image
im = Image.open('output14024671122-1021-094450-118_p001.tif')
im.save('test.tif')

Exception:

[root@app02 pil-page-test]# python tif-test.py 
Traceback (most recent call last):
  File "tif-test.py", line 4, in <module>
    im.save('test.tif')
  File "/usr/lib64/python2.7/site-packages/PIL/Image.py", line 1685, in save
    save_handler(self, fp, filename)
  File "/usr/lib64/python2.7/site-packages/PIL/TiffImagePlugin.py", line 1161, in _save
    atts[k] = float(v[0])/float(v[1])
ZeroDivisionError: float division by zero

TiffInfo on the input file:

TIFF Directory at offset 0x8 (8)
  Subfile Type: multi-page document (2 = 0x2)
  Image Width: 1728 Image Length: 2202
  Resolution: 204, 196 pixels/inch
  Bits/Sample: 1
  Compression Scheme: CCITT Group 3
  Photometric Interpretation: min-is-white
  FillOrder: msb-to-lsb
  Orientation: row 0 top, col 0 lhs
  Samples/Pixel: 1
  Rows/Strip: 4854
  Planar Configuration: single image plane
  Page Number: 0-0
  Software: GPL Ghostscript 9.07
  DateTime: 2014:10:25 11:08:31
  Group 3 Options: EOL padding (4 = 0x4)

According to the spec, the second value in the page number can be "0" indicating that the maximum number of pages is not available.

http://www.awaresystems.be/imaging/tiff/tifftags/pagenumber.html

Not sure what the actual fix is, but wanted to log this with my research thus far.

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugAny unexpected behavior, until confirmed feature.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions