Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do not use CCITTFaxDecode filter if libtiff is not available #6518

Merged
merged 1 commit into from Aug 31, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions Tests/test_file_pdf.py
Expand Up @@ -6,7 +6,7 @@

import pytest

from PIL import Image, PdfParser
from PIL import Image, PdfParser, features

from .helper import hopper, mark_if_feature_version

Expand Down Expand Up @@ -43,7 +43,7 @@ def test_monochrome(tmp_path):

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


def test_greyscale(tmp_path):
Expand Down
33 changes: 18 additions & 15 deletions src/PIL/PdfImagePlugin.py
Expand Up @@ -25,7 +25,7 @@
import os
import time

from . import Image, ImageFile, ImageSequence, PdfParser, __version__
from . import Image, ImageFile, ImageSequence, PdfParser, __version__, features

#
# --------------------------------------------------------------------
Expand Down Expand Up @@ -130,20 +130,23 @@ def _save(im, fp, filename, save_all=False):
width, height = im.size

if im.mode == "1":
filter = "CCITTFaxDecode"
bits = 1
params = PdfParser.PdfArray(
[
PdfParser.PdfDict(
{
"K": -1,
"BlackIs1": True,
"Columns": width,
"Rows": height,
}
)
]
)
if features.check("libtiff"):
filter = "CCITTFaxDecode"
bits = 1
params = PdfParser.PdfArray(
[
PdfParser.PdfDict(
{
"K": -1,
"BlackIs1": True,
"Columns": width,
"Rows": height,
}
)
]
)
else:
filter = "DCTDecode"
colorspace = PdfParser.PdfName("DeviceGray")
procset = "ImageB" # grayscale
elif im.mode == "L":
Expand Down