Merge pull request #5430 from radarhere/pdf_1

Switched to saving 1-bit PDFs with DCTDecode
This commit is contained in:
Hugo van Kemenade 2021-04-25 15:29:34 +03:00 committed by GitHub
commit dc817ead76
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 3 additions and 8 deletions

View File

@ -42,7 +42,8 @@ def test_monochrome(tmp_path):
mode = "1"
# Act / Assert
helper_save_as_pdf(tmp_path, mode)
outfile = helper_save_as_pdf(tmp_path, mode)
assert os.path.getsize(outfile) < 15000
def test_greyscale(tmp_path):

View File

@ -124,7 +124,7 @@ def _save(im, fp, filename, save_all=False):
decode = None
if im.mode == "1":
filter = "ASCIIHexDecode"
filter = "DCTDecode"
colorspace = PdfParser.PdfName("DeviceGray")
procset = "ImageB" # grayscale
bits = 1
@ -161,12 +161,6 @@ def _save(im, fp, filename, save_all=False):
op = io.BytesIO()
if filter == "ASCIIHexDecode":
if bits == 1:
# 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", im.size)
im.putdata(data)
ImageFile._save(im, op, [("hex", (0, 0) + im.size, 0, im.mode)])
elif filter == "DCTDecode":
Image.SAVE["JPEG"](im, op, filename)