Fix `ValueError` when extracting images, due to breaking changes in Pillow (#827)
* Fix #795 * Update CHANGELOG.md Co-authored-by: Kunal Gehlot <kunal.g@360hvpl.com>pull/829/head
parent
769dbb6343
commit
fa71062c35
|
@ -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
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue