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

Ignore compression value from BMP info dictionary when saving as TIFF #6231

Merged
merged 1 commit into from May 20, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 7 additions & 0 deletions Tests/test_file_tiff.py
Expand Up @@ -690,6 +690,13 @@ def test_save_icc_profile(self, tmp_path):
with Image.open(outfile) as reloaded:
assert reloaded.info["icc_profile"] == icc_profile

def test_save_bmp_compression(self, tmp_path):
with Image.open("Tests/images/hopper.bmp") as im:
assert im.info["compression"] == 0

outfile = str(tmp_path / "temp.tif")
im.save(outfile)

def test_discard_icc_profile(self, tmp_path):
outfile = str(tmp_path / "temp.tif")

Expand Down
8 changes: 7 additions & 1 deletion src/PIL/TiffImagePlugin.py
Expand Up @@ -1568,7 +1568,13 @@ def _save(im, fp, filename):

encoderinfo = im.encoderinfo
encoderconfig = im.encoderconfig
compression = encoderinfo.get("compression", im.info.get("compression"))
try:
compression = encoderinfo["compression"]
except KeyError:
compression = im.info.get("compression")
if isinstance(compression, int):
# compression value may be from BMP. Ignore it
compression = None
if compression is None:
compression = "raw"
elif compression == "tiff_jpeg":
Expand Down