mirror of
https://github.com/python-pillow/Pillow.git
synced 2025-01-27 01:34:24 +03:00
Merge pull request #976 from hugovk/tiff_ints
Fix saving TIFF with PageNumber total = 0
This commit is contained in:
commit
72c6db99df
|
@ -1153,8 +1153,11 @@ def _save(im, fp, filename):
|
||||||
# following tiffcp.c->cpTag->TIFF_RATIONAL
|
# following tiffcp.c->cpTag->TIFF_RATIONAL
|
||||||
atts[k] = float(v[0][0])/float(v[0][1])
|
atts[k] = float(v[0][0])/float(v[0][1])
|
||||||
continue
|
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?
|
# List of ints?
|
||||||
|
# Avoid divide by zero in next if-clause
|
||||||
if type(v[0]) in (int, float):
|
if type(v[0]) in (int, float):
|
||||||
atts[k] = list(v)
|
atts[k] = list(v)
|
||||||
continue
|
continue
|
||||||
|
|
BIN
Tests/images/total-pages-zero.tif
Normal file
BIN
Tests/images/total-pages-zero.tif
Normal file
Binary file not shown.
|
@ -299,6 +299,26 @@ class TestFileTiff(PillowTestCase):
|
||||||
self.assertEqual(ret, [0, 1])
|
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(outfile)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
unittest.main()
|
unittest.main()
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user