Skip to content

Commit 49617ba

Browse files
committed
Do not use CCITTFaxDecode filter if libtiff is not available
1 parent 4c59f77 commit 49617ba

File tree

2 files changed

+19
-16
lines changed

2 files changed

+19
-16
lines changed

Tests/test_file_pdf.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ def test_monochrome(tmp_path):
4343

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

4848

4949
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)