Skip to content

Improve reading XPM images #8874

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

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open

Conversation

radarhere
Copy link
Member

@radarhere radarhere commented Apr 9, 2025

Resolves #8872

Looking at the specification, or even just looking at https://github.com/python-pillow/Pillow/blob/main/Tests/images/hopper.xpm#L50), you will see that an XPM image describes a palette with a series of keys and values, and then lists the pixel values within lines separated by quotes and commas. Our "raw" decoder cannot handle this pixel data, and I've created a Python decoder instead.

I've also pushed commits to read an image as RGB if the palette is larger than 256 colours (test image from the user in the issue), or if the palette keys are longer than a single character (test image created by ImageMagick), removing this error.

if pal > 256 or bpp != 1:
msg = "cannot read this XPM file"
raise ValueError(msg)

@radarhere radarhere changed the title Improved reading XPM images Improve reading XPM images Apr 19, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

ImageGrab.grabclipboard raises ValueError: cannot read this XPM file
1 participant