Skip to content

Commit

Permalink
Merge pull request #3827 from radarhere/pdf
Browse files Browse the repository at this point in the history
Fixed dimensions of 1-bit PDFs
  • Loading branch information
hugovk committed May 4, 2019
2 parents 9a25b3c + ae1f7c4 commit d45a13d
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
5 changes: 5 additions & 0 deletions Tests/test_file_pdf.py
Expand Up @@ -26,6 +26,11 @@ def helper_save_as_pdf(self, mode, **kwargs):
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

Expand Down
2 changes: 1 addition & 1 deletion src/PIL/PdfImagePlugin.py
Expand Up @@ -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":
Expand Down

0 comments on commit d45a13d

Please sign in to comment.