Merge pull request #3137 from radarhere/pdf

Fixed saving a multiframe image as a single frame PDF
This commit is contained in:
Hugo 2018-07-01 22:18:48 +03:00 committed by GitHub
commit c222df2b56
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 1 deletions

View File

@ -104,6 +104,16 @@ class TestFilePdf(PillowTestCase):
self.assertTrue(os.path.isfile(outfile))
self.assertGreater(os.path.getsize(outfile), 0)
def test_multiframe_normal_save(self):
# Test saving a multiframe image without save_all
im = Image.open("Tests/images/dispose_bgnd.gif")
outfile = self.tempfile('temp.pdf')
im.save(outfile)
self.assertTrue(os.path.isfile(outfile))
self.assertGreater(os.path.getsize(outfile), 0)
def test_pdf_open(self):
# fail on a buffer full of null bytes
self.assertRaises(PdfParser.PdfFormatError, PdfParser.PdfParser, buf=bytearray(65536))

View File

@ -113,7 +113,8 @@ def _save(im, fp, filename, save_all=False):
pageNumber = 0
for imSequence in ims:
for im in ImageSequence.Iterator(imSequence):
im_pages = ImageSequence.Iterator(imSequence) if save_all else [imSequence]
for im in im_pages:
# FIXME: Should replace ASCIIHexDecode with RunLengthDecode (packbits)
# or LZWDecode (tiff/lzw compression). Note that PDF 1.2 also supports
# Flatedecode (zip compression).