Fixed dimensions of 1-bit PDFs

This commit is contained in:
Andrew Murray 2019-04-30 15:31:47 +10:00
parent c15dc4d7ca
commit ae1f7c4f50
2 changed files with 6 additions and 1 deletions

View File

@ -26,6 +26,11 @@ class TestFilePdf(PillowTestCase):
self.assertGreater(len(pdf.pages), 1)
else:
self.assertGreater(len(pdf.pages), 0)
with open(outfile, 'rb') as fp:
contents = fp.read()
size = tuple(int(d) for d in
contents.split(b'/MediaBox [ 0 0 ')[1].split(b']')[0].split())
self.assertEqual(im.size, size)
return outfile

View File

@ -166,7 +166,7 @@ def _save(im, fp, filename, save_all=False):
# FIXME: the hex encoder doesn't support packed 1-bit
# images; do things the hard way...
data = im.tobytes("raw", "1")
im = Image.new("L", (len(data), 1), None)
im = Image.new("L", im.size)
im.putdata(data)
ImageFile._save(im, op, [("hex", (0, 0)+im.size, 0, im.mode)])
elif filter == "DCTDecode":