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

Use palette when loading ICO images #7798

Merged
merged 1 commit into from Mar 11, 2024
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
11 changes: 11 additions & 0 deletions Tests/test_file_ico.py
Expand Up @@ -38,6 +38,17 @@ def test_black_and_white() -> None:
assert im.size == (16, 16)


def test_palette(tmp_path: Path) -> None:
temp_file = str(tmp_path / "temp.ico")

im = Image.new("P", (16, 16))
im.save(temp_file)

with Image.open(temp_file) as reloaded:
assert reloaded.mode == "P"
assert reloaded.palette is not None


def test_invalid_file() -> None:
with open("Tests/images/flower.jpg", "rb") as fp:
with pytest.raises(SyntaxError):
Expand Down
2 changes: 2 additions & 0 deletions src/PIL/IcoImagePlugin.py
Expand Up @@ -329,6 +329,8 @@ def load(self):
self.im = im.im
self.pyaccess = None
self._mode = im.mode
if im.palette:
self.palette = im.palette
if im.size != self.size:
warnings.warn("Image was not the expected size")

Expand Down