diff --git a/Tests/test_file_blp.py b/Tests/test_file_blp.py index 86f208729f7..c1fae44ca35 100644 --- a/Tests/test_file_blp.py +++ b/Tests/test_file_blp.py @@ -31,19 +31,21 @@ def test_load_blp2_dxt1a(): def test_save(tmp_path): - im = hopper("P") f = str(tmp_path / "temp.blp") - im.save(f) - with Image.open(f) as reloaded: - assert_image_equal(im.convert("RGB"), reloaded) - - with Image.open("Tests/images/transparent.png") as im: - f = str(tmp_path / "temp.blp") - im.convert("P").save(f) + for version in ("BLP1", "BLP2"): + im = hopper("P") + im.save(f, blp_version=version) with Image.open(f) as reloaded: - assert_image_similar(im, reloaded, 8) + assert_image_equal(im.convert("RGB"), reloaded) + + with Image.open("Tests/images/transparent.png") as im: + f = str(tmp_path / "temp.blp") + im.convert("P").save(f, blp_version=version) + + with Image.open(f) as reloaded: + assert_image_similar(im, reloaded, 8) im = hopper() with pytest.raises(ValueError): diff --git a/src/PIL/BlpImagePlugin.py b/src/PIL/BlpImagePlugin.py index bfa5c78e922..d28471a6f68 100644 --- a/src/PIL/BlpImagePlugin.py +++ b/src/PIL/BlpImagePlugin.py @@ -479,13 +479,18 @@ def _save(im, fp, filename, save_all=False): if im.mode != "P": raise ValueError("Unsupported BLP image mode") - fp.write(b"BLP2") + magic = b"BLP1" if im.encoderinfo.get("blp_version") == "BLP1" else b"BLP2" + fp.write(magic) + fp.write(struct.pack("