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

Image.MIME populated unexpectedly #7398

Closed
cjuracek opened this issue Sep 15, 2023 · 2 comments · Fixed by #7399
Closed

Image.MIME populated unexpectedly #7398

cjuracek opened this issue Sep 15, 2023 · 2 comments · Fixed by #7399

Comments

@cjuracek
Copy link

What did you do?

Attempt to get mapping from MIME type to PIL format via PIL.Image.MIME

What did you expect to happen?

A filled dictionary mapping from MIME type to PIL format.

What actually happened?

Empty dict. It looks like PIL.Image.init() populates this registry.

It's understandable if this method needs to be called before the MIME registry is populated. But some documentation surrounding this and the MIME variable would be useful. I was especially surprised when PIL.features.pilinfo() populated this variable as a side effect.

What are your OS, Python and Pillow versions?

  • OS: macOS Monterey 12.6.8
  • Python: 3.8.15
  • Pillow: 10.0.0
if __name__ == "__main__":
    print(f"PIL.Image.MIME before pilinfo(): {Image.MIME}")
    features.pilinfo()
    print(f"PIL.Image.MIME after pilinfo(): {Image.MIME}")
@radarhere
Copy link
Member

radarhere commented Sep 15, 2023

What do you think of #7399? With it, you should be able to go to the documentation for the Image module, search for "MIME" and find this screen telling you everything you need to know -

  • register_mime() tells you that it populates Image.MIME
  • The 'Note' tells you that register_mime() is called by preinit() or init()
  • init() tells you that it is called when opening, saving or by features.pilinfo()

Screenshot 2023-09-16 at 9 33 16 am

@cjuracek
Copy link
Author

That looks good - maybe better documentation on this was all I was looking for.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants