Skip to content

Commit

Permalink
Merge 6ec6b16 into 8b7a989
Browse files Browse the repository at this point in the history
  • Loading branch information
hugovk committed Oct 26, 2014
2 parents 8b7a989 + 6ec6b16 commit c09fd54
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 1 deletion.
5 changes: 4 additions & 1 deletion PIL/TiffImagePlugin.py
Expand Up @@ -1153,8 +1153,11 @@ def _save(im, fp, filename):
# following tiffcp.c->cpTag->TIFF_RATIONAL
atts[k] = float(v[0][0])/float(v[0][1])
continue
if type(v) == tuple and len(v) > 2:
if (type(v) == tuple and
(len(v) > 2 or
(len(v) == 2 and v[1] == 0))):
# List of ints?
# Avoid divide by zero in next if-clause
if type(v[0]) in (int, float):
atts[k] = list(v)
continue
Expand Down
Binary file added Tests/images/total-pages-zero.tif
Binary file not shown.
20 changes: 20 additions & 0 deletions Tests/test_file_tiff.py
Expand Up @@ -299,6 +299,26 @@ def test__cvt_res_sequence(self):
self.assertEqual(ret, [0, 1])


def test_page_number_x_0(self):
# Issue 973
# Test TIFF with tag 297 (Page Number) having value of 0 0.
# The first number is the current page number.
# The second is the total number of pages, zero means not available.

# Arrange
outfile = self.tempfile("temp.tif")

# Created by printing a page in Chrome to PDF, then:
# /usr/bin/gs -q -sDEVICE=tiffg3 -sOutputFile=total-pages-zero.tif
# -dNOPAUSE /tmp/test.pdf -c quit
infile = "Tests/images/total-pages-zero.tif"
im = Image.open(infile)

# Act / Assert
# Should not divide by zero
im.save("test.tif")


if __name__ == '__main__':
unittest.main()

Expand Down

0 comments on commit c09fd54

Please sign in to comment.