Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions Tests/test_file_png.py
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,15 @@ def test_save_grayscale_transparency(self, tmp_path: Path) -> None:
assert colors is not None
assert colors[0][0] == num_transparent

def test_save_1_transparency(self, tmp_path: Path) -> None:
out = tmp_path / "temp.png"

im = Image.new("1", (1, 1), 1)
im.save(out, transparency=1)

with Image.open(out) as reloaded:
assert reloaded.info["transparency"] == 255

def test_save_rgb_single_transparency(self, tmp_path: Path) -> None:
in_file = "Tests/images/caption_6_33_22.png"
with Image.open(in_file) as im:
Expand Down
4 changes: 3 additions & 1 deletion src/PIL/PngImagePlugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -509,7 +509,9 @@ def chunk_tRNS(self, pos: int, length: int) -> bytes:
# otherwise, we have a byte string with one alpha value
# for each palette entry
self.im_info["transparency"] = s
elif self.im_mode in ("1", "L", "I;16"):
elif self.im_mode == "1":
self.im_info["transparency"] = 255 if i16(s) else 0
elif self.im_mode in ("L", "I;16"):
self.im_info["transparency"] = i16(s)
elif self.im_mode == "RGB":
self.im_info["transparency"] = i16(s), i16(s, 2), i16(s, 4)
Expand Down
Loading