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

Exceptions when trying to convert BMP to TIFF #6230

Closed
sekrause opened this issue Apr 20, 2022 · 2 comments · Fixed by #6232
Closed

Exceptions when trying to convert BMP to TIFF #6230

sekrause opened this issue Apr 20, 2022 · 2 comments · Fixed by #6232

Comments

@sekrause
Copy link

https://stuff.realpath.org/test.bmp is a very simple BMP image (unfortunately GitHub doesn't allow to attach it here).

First exception

When I try to convert it to a TIFF:

with Image.open("test.bmp") as im:
    im.save("test.tiff", format="TIFF")

I get the following exception:

Traceback (most recent call last):
  File "convert.py", line 4, in <module>
    im.save("test.tiff", format="TIFF")
  File "venv\lib\site-packages\PIL\Image.py", line 2300, in save
    save_handler(self, fp, filename)
  File "venv\lib\site-packages\PIL\TiffImagePlugin.py", line 1810, in _save
    e = Image._getencoder(im.mode, "libtiff", a, encoderconfig)
  File "venv\lib\site-packages\PIL\Image.py", line 458, in _getencoder
    return encoder(mode, *args + extra)
TypeError: argument 3 must be str, not int

However when disabling compression it works:

with Image.open("test.bmp") as im:
    im.save("test.tiff", format="TIFF", compression=None)

This seems to be an older issue because I found a StackOverflow question from 2019 mentioning this exact problem: https://stackoverflow.com/q/54181211

Second exception

There also seems to be a regression in 9.1.0 compared to 9.0.1. In 9.0.1 using tiff_lzw compression worked without problems:

with Image.open("test.bmp") as im:
    im.save("test.tiff", format="TIFF", compression="tiff_lzw")

However in 9.1.0 I get the following exception:

Traceback (most recent call last):
  File "convert.py", line 4, in <module>
    im.save("test.tiff", format="TIFF", compression="tiff_lzw")
  File "venv\lib\site-packages\PIL\Image.py", line 2300, in save
    save_handler(self, fp, filename)
  File "venv\lib\site-packages\PIL\TiffImagePlugin.py", line 1810, in _save
    e = Image._getencoder(im.mode, "libtiff", a, encoderconfig)
  File "venv\lib\site-packages\PIL\Image.py", line 458, in _getencoder
    return encoder(mode, *args + extra)
ValueError: Requiring 768 items for Colormap

OS, Python and Pillow versions:

  • OS: Windows 10
  • Python: 3.9 x64
  • Pillow: 9.1.0
@radarhere
Copy link
Member

I've created #6231 to fix the first part.

@radarhere
Copy link
Member

I've created PR #6232 to fix the second part.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants