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

Added ICO saving in BMP format #5513

Merged
merged 2 commits into from Jun 6, 2021
Merged

Conversation

radarhere
Copy link
Member

Resolves #2512

ICO can either be a container for PNG or BMP.

Pillow has been saving ICOs only in the PNG format. This PR adds support for saving ICOs with the BMP format, largely by reversing the process that we use to load the BMP format. It would be called with im.save("out.ico", bitmap_format="bmp")

Comment on lines +81 to +84
and_mask = Image.new("1", tmp.size)
ImageFile._save(
and_mask, image_io, [("raw", (0, 0) + tmp.size, 0, ("1", 0, -1))]
)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Our 1, L, P and RGB modes don't have any transparency, so the AND mask can just be constant.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will transparency still work for BMP-formatted ICO images?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

RGBA images saved to BMP-formatted ICO will have transparency, because 32-bit images don't require the AND mask (see https://en.wikipedia.org/wiki/ICO_(file_format) for more information).

@hugovk
Copy link
Member

hugovk commented Jun 6, 2021

Looks good, let's also add to release notes.

@radarhere
Copy link
Member Author

Done.

@hugovk hugovk merged commit 2a7eb54 into python-pillow:master Jun 6, 2021
@hugovk
Copy link
Member

hugovk commented Jun 6, 2021

Thank you!

@radarhere radarhere deleted the ico_bmp branch June 6, 2021 22:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support saving uncompressed ICO
3 participants