Skip to content

Commit

Permalink
Merge pull request #6231 from radarhere/bmp_compression
Browse files Browse the repository at this point in the history
Ignore compression value from BMP info dictionary when saving as TIFF
  • Loading branch information
hugovk committed May 20, 2022
2 parents 89f5a7d + 2c5e504 commit 33f00c9
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
7 changes: 7 additions & 0 deletions Tests/test_file_tiff.py
Expand Up @@ -715,6 +715,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 @@ -1559,7 +1559,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

0 comments on commit 33f00c9

Please sign in to comment.