Skip to content

Commit

Permalink
Fix #795
Browse files Browse the repository at this point in the history
  • Loading branch information
Kunal Gehlot committed Aug 23, 2022
1 parent ad6587c commit cac6217
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
- 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))
- `ValueError` when extracting images, due to breaking changes in Pillow ([#795](https://github.com/pdfminer/pdfminer.six/issues/795))

### Deprecated

Expand Down
8 changes: 6 additions & 2 deletions pdfminer/image.py
Original file line number Diff line number Diff line change
Expand Up @@ -225,20 +225,24 @@ def _save_bytes(self, image: LTImage) -> str:
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
Expand Down

0 comments on commit cac6217

Please sign in to comment.