Fixed saving a multiframe image as a single frame PDF

This commit is contained in:
Andrew Murray 2018-05-18 22:15:45 +10:00
parent 5ca35bbcb3
commit 3bbd0a5810
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).