diff --git a/Tests/test_file_pdf.py b/Tests/test_file_pdf.py index 7b024426b..983bfffe7 100644 --- a/Tests/test_file_pdf.py +++ b/Tests/test_file_pdf.py @@ -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 diff --git a/src/PIL/PdfImagePlugin.py b/src/PIL/PdfImagePlugin.py index 702aaa392..7b92a83ae 100644 --- a/src/PIL/PdfImagePlugin.py +++ b/src/PIL/PdfImagePlugin.py @@ -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":