diff --git a/CHANGELOG.md b/CHANGELOG.md index dfe31f1..abc7362 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -18,7 +18,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). - `TypeError` when getting default width of font ([#720](https://github.com/pdfminer/pdfminer.six/issues/720)) - Installing typing-extensions on Python 3.6 and 3.7 ([#775](https://github.com/pdfminer/pdfminer.six/pull/775)) - `TypeError` in cmapdb.py when parsing null characters ([#768](https://github.com/pdfminer/pdfminer.six/pull/768)) -- Color "convenience operators" now (per spec) also set color space ([#779](https://github.com/pdfminer/pdfminer.six/issues/779)) +- Color "convenience operators" now (per spec) also set color space ([#794](https://github.com/pdfminer/pdfminer.six/pull/794)) +- `ValueError` when extracting images, due to breaking changes in Pillow ([#827](https://github.com/pdfminer/pdfminer.six/pull/827)) ### Deprecated diff --git a/pdfminer/image.py b/pdfminer/image.py index 54b1492..61c2673 100644 --- a/pdfminer/image.py +++ b/pdfminer/image.py @@ -225,20 +225,24 @@ class ImageWriter: with open(path, "wb") as fp: try: from PIL import Image # type: ignore[import] + from PIL import ImageOps except ImportError: raise ImportError(PIL_ERROR_MESSAGE) - mode: Literal["1", "8", "RGB", "CMYK"] + mode: Literal["1", "L", "RGB", "CMYK"] if image.bits == 1: mode = "1" elif image.bits == 8 and channels == 1: - mode = "8" + mode = "L" elif image.bits == 8 and channels == 3: mode = "RGB" elif image.bits == 8 and channels == 4: mode = "CMYK" img = Image.frombytes(mode, image.srcsize, image.stream.get_data(), "raw") + if mode == "L": + img = ImageOps.invert(img) + img.save(fp) return name