Skip to content

Commit

Permalink
Merge pull request #5667 from radarhere/ico
Browse files Browse the repository at this point in the history
Read ICO AND mask from end
  • Loading branch information
hugovk committed Sep 5, 2021
2 parents 65b5f91 + cbdc751 commit a918186
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 1 deletion.
Binary file added Tests/images/hopper_mask.ico
Binary file not shown.
Binary file added Tests/images/hopper_mask.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 5 additions & 0 deletions Tests/test_file_ico.py
Expand Up @@ -18,6 +18,11 @@ def test_sanity():
assert im.get_format_mimetype() == "image/x-icon"


def test_mask():
with Image.open("Tests/images/hopper_mask.ico") as im:
assert_image_equal_tofile(im, "Tests/images/hopper_mask.png")


def test_black_and_white():
with Image.open("Tests/images/black_and_white.ico") as im:
assert im.mode == "RGBA"
Expand Down
2 changes: 1 addition & 1 deletion src/PIL/IcoImagePlugin.py
Expand Up @@ -235,8 +235,8 @@ def frame(self, idx):
# the total mask data is
# padded row size * height / bits per char

and_mask_offset = o + int(im.size[0] * im.size[1] * (bpp / 8.0))
total_bytes = int((w * im.size[1]) / 8)
and_mask_offset = header["offset"] + header["size"] - total_bytes

self.buf.seek(and_mask_offset)
mask_data = self.buf.read(total_bytes)
Expand Down

0 comments on commit a918186

Please sign in to comment.