Skip to content

Commit b953f73

Browse files
authored
Merge pull request #6518 from radarhere/pdf_ccittfaxdecode
2 parents b607e83 + 3b4ea7c commit b953f73

2 files changed

Lines changed: 20 additions & 17 deletions

File tree

Tests/test_file_pdf.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
import pytest
88

9-
from PIL import Image, PdfParser
9+
from PIL import Image, PdfParser, features
1010

1111
from .helper import hopper, mark_if_feature_version
1212

@@ -44,7 +44,7 @@ def test_monochrome(tmp_path):
4444

4545
# Act / Assert
4646
outfile = helper_save_as_pdf(tmp_path, mode)
47-
assert os.path.getsize(outfile) < 5000
47+
assert os.path.getsize(outfile) < (5000 if features.check("libtiff") else 15000)
4848

4949

5050
def test_greyscale(tmp_path):

src/PIL/PdfImagePlugin.py

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
import os
2626
import time
2727

28-
from . import Image, ImageFile, ImageSequence, PdfParser, __version__
28+
from . import Image, ImageFile, ImageSequence, PdfParser, __version__, features
2929

3030
#
3131
# --------------------------------------------------------------------
@@ -130,20 +130,23 @@ def _save(im, fp, filename, save_all=False):
130130
width, height = im.size
131131

132132
if im.mode == "1":
133-
filter = "CCITTFaxDecode"
134-
bits = 1
135-
params = PdfParser.PdfArray(
136-
[
137-
PdfParser.PdfDict(
138-
{
139-
"K": -1,
140-
"BlackIs1": True,
141-
"Columns": width,
142-
"Rows": height,
143-
}
144-
)
145-
]
146-
)
133+
if features.check("libtiff"):
134+
filter = "CCITTFaxDecode"
135+
bits = 1
136+
params = PdfParser.PdfArray(
137+
[
138+
PdfParser.PdfDict(
139+
{
140+
"K": -1,
141+
"BlackIs1": True,
142+
"Columns": width,
143+
"Rows": height,
144+
}
145+
)
146+
]
147+
)
148+
else:
149+
filter = "DCTDecode"
147150
colorspace = PdfParser.PdfName("DeviceGray")
148151
procset = "ImageB" # grayscale
149152
elif im.mode == "L":

0 commit comments

Comments
 (0)