Skip to content

Commit

Permalink
Added saving LA images as PDFs
Browse files Browse the repository at this point in the history
  • Loading branch information
radarhere committed Jul 22, 2023
1 parent c108d9d commit 0a0a3fc
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 5 deletions.
9 changes: 5 additions & 4 deletions Tests/test_file_pdf.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,9 @@ def test_save(tmp_path, mode):


@skip_unless_feature("jpg_2000")
def test_save_rgba(tmp_path):
helper_save_as_pdf(tmp_path, "RGBA")
@pytest.mark.parametrize("mode", ("LA", "RGBA"))
def test_save_alpha(tmp_path, mode):
helper_save_as_pdf(tmp_path, mode)


def test_monochrome(tmp_path):
Expand All @@ -57,8 +58,8 @@ def test_monochrome(tmp_path):


def test_unsupported_mode(tmp_path):
im = hopper("LA")
outfile = str(tmp_path / "temp_LA.pdf")
im = hopper("PA")
outfile = str(tmp_path / "temp_PA.pdf")

with pytest.raises(ValueError):
im.save(outfile)
Expand Down
2 changes: 1 addition & 1 deletion docs/handbook/image-file-formats.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1486,7 +1486,7 @@ files. Different encoding methods are used, depending on the image mode.
unavailable
* L, RGB and CMYK mode images use JPEG encoding
* P mode images use HEX encoding
* RGBA mode images use JPEG2000 encoding
* LA and RGBA mode images use JPEG2000 encoding

.. _pdf-saving:

Expand Down
5 changes: 5 additions & 0 deletions src/PIL/PdfImagePlugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,11 @@ def _save(im, fp, filename, save_all=False):
# params = f"<< /Predictor 15 /Columns {width-2} >>"
colorspace = PdfParser.PdfName("DeviceGray")
procset = "ImageB" # grayscale
elif im.mode == "LA":
filter = "JPXDecode"
# params = f"<< /Predictor 15 /Columns {width-2} >>"
colorspace = PdfParser.PdfName("DeviceGray")
procset = "ImageB" # grayscale
elif im.mode == "P":
filter = "ASCIIHexDecode"
palette = im.getpalette()
Expand Down

0 comments on commit 0a0a3fc

Please sign in to comment.